Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
1.22/5 (3 votes)
Hello Team,

I have the Stored Procedure as follows.it gives me the record which is less than today date.

SQL
select count(c.ID) as [RECORDCOUNT], U.NETWORKID
from CUSTOMERLOANDATA C (nolock)
Inner Join USERMASTER U (nolock) on U.Id = C.QCUSERID
where convert(varchar(10),C.UpdatedON,120) < CONVERT(VARCHAR(10), GETDATE(),120)
ANd isnull(c.QCPRocessed,0) = 1
group by U.NETWORKID
order by U.NETWORKID


I want record for today date as well, but if i make a changes in where condition for getting the today date record it showing me blank .I have tried this .
SQL
select count(c.ID) as [RECORDCOUNT], U.NETWORKID
from CUSTOMERLOANDATA C (nolock)
Inner Join USERMASTER U (nolock) on U.Id = C.QCUSERID
where convert(varchar(10),C.UpdatedON,120) = CONVERT(VARCHAR(10), GETDATE(),120)
ANd isnull(c.QCPRocessed,0) = 1
group by U.NETWORKID
order by U.NETWORKID


where exactly i am getting wrong.Please Tell me.
Thanks
Harshal
Posted
Comments
Maciej Los 3-Mar-14 10:51am    
What kind of data are stored in UpdatedON? VARCHAR or DATETIME?
R Harshal 3-Mar-14 10:54am    
datetime.

Try:
SQL
where convert(varchar(10),C.UpdatedON,120) <= CONVERT(VARCHAR(10), GETDATE(),120)

But... if UpdatedOn is a DateTime field, then don;t convert it as it will give bad results. Compare two DateTimes directly:
SQL
where C.UpdatedON <= GETDATE()
 
Share this answer
 
Comments
R Harshal 3-Mar-14 11:20am    
Sorry to say Buddy but it dont work .it not giving me today record.it gives me less than today record .
OriginalGriff 3-Mar-14 11:31am    
Ah! Simple: use DATEDIFF instead:
WHERE DATEDIFF(d, C.UpdatedON, GETDATE()) >= 0
Andrius Leonavicius 3-Mar-14 13:22pm    
Wow, your proposed solution is really simpler than mine. I like it. :)
R Harshal 3-Mar-14 11:40am    
No use Sir.it wont work.
R Harshal 3-Mar-14 11:42am    
it still give me less than getdate record.i want today date record as well.
Hi,

Instead of this:
SQL
where convert(varchar(10),C.UpdatedON,120) = CONVERT(VARCHAR(10), GETDATE(),120)

you could do something like this:
SQL
WHERE DATEADD(dd, 0, DATEDIFF(dd, 0, C.UpdatedON)) = DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE()))

Note: instead of "=" sign you may want to use "<=" for less than today including today.

Please let me know if this solved your problem.
 
Share this answer
 
Comments
R Harshal 3-Mar-14 11:19am    
Sorry to say Buddy but it dont work .it not giving me today record.it gives me less than today record .
R Harshal 3-Mar-14 11:42am    
it give me less than getdate record.i want today date record as well.
Andrius Leonavicius 3-Mar-14 12:59pm    
Are you sure you have records, which satisfies both WHERE conditions: date comparison and isnull(c.QCPRocessed,0) = 1?
Could you post some sample data for testing?
R Harshal 4-Mar-14 2:12am    
yes it satisfies the both where condition..Please can you help me further..
R Harshal 4-Mar-14 2:40am    
how foolish i am.
the problem is i have not updated the qcuserid (that why i am not getting the today record )
sorry to disturb you by saying not getting the answer.
Thank you so much for your help Buddy.

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