Click here to Skip to main content
15,889,992 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
I have a certain values as "new , complete , inprogress , deleted" in table.
I need to count each string when there is a entry with respect to the current date.
Could any one help me..
Posted
Updated 30-Sep-14 11:58am
v2
Comments
Simon_Whale 30-Sep-14 18:19pm    
is this in a generic collection or do you want to execute this against the database?
PIEBALDconsult 30-Sep-14 19:06pm    
I hope you are storing dates as dates and not as strings; if not, you're hosed.
AndrewCharlz 1-Oct-14 2:44am    
what is ur requirement or task

Note that this is for MS SQL Server - you didn't specify which database.
status is your field that contains new, complete, etc...


SQL
DECLARE @dt datetime
SET @dt = GetDate()

SELECT status, COUNT(*) FROM your_table 
WHERE your_date_field = CONVERT(datetime, @dt, 104)
GROUP BY status



Note that it would be better to have status table something like
PK        code        value
----------------------------
10        new         New
20        compl       Complete
30        inpr        In progress


I use code field if I need Enum names or some other no-user-needs-to-see-it task...while value is something to show the user. Number is used for combobox /radio button lists, sorting, etc...

Advantages are
a) you can easily sort by your integer primary key.
b) You can easily add in-between statuses if someone gets new idea.
c) You're not bound to exactly typing the word and worrying about case sensitive comparisons.
d) You can show your user whatever text you want without changing single line of code.

Disadvantage is that you have to link the table if you need the name (or write the function that returns the name for any given PK) - this is what I did :)
 
Share this answer
 
v3
SQL
string strQury = "select count(*) from sqsh.view_smartopd where servicedisplayname = '" + strDocName + "' and tokendate = '" + dt + "' and value = 'new';";
           

countNew = rdr.GetInt32("count(*)");
txtTotalPatient.Text = countNew.ToString()
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900