sql server - counting with the right date c# -
i created application send email summary of service status , total number of service. email must send every 12 a.m. in each day example give summary shown in queries. problem, queries counting services include services have done in previous dates! how alter query make count every day i.e. summary of counts each date? appreciated!
string connectionstring = @"data source= (localdb)\projects;initial catalog=databasee; integrated security=true;connect timeout=30;encrypt=false;"; sqldatareader reader; string sendmessage = @"select (select count (*) service done = 3) countdone, (select count(*) service undone = 5) countundone"; using (sqlconnection mycon = new sqlconnection(connectionstring)) { //open connection string mycon.open(); sqlcommand cmd = new sqlcommand(sendmessage, mycon); arraylist emailarray = new arraylist(); reader = cmd.executereader(); var email = new list<emailsend>(); //counter int countdone = -1, countundone = -1; if (reader.read()) { countdone = (int)reader["countdone"]; countundone = (int)reader["countundone"]; } int totaldoneandundone = countdone + countundone;
well, should consider changing query like
select (select count (*) service done = 3 , convert(date, your_datecolumn) = convert(date, getdate()) countdone, (select count(*) service undone = 5 , convert(date, your_datecolumn) = convert(date, getdate()) countundone
Comments
Post a Comment