Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Date comparison problem

Author  Topic 

mattech13
Starting Member

4 Posts

Posted - 2013-09-15 : 08:10:31
Hi,

date format's, I love em ;)

I have this code..


Select ReferralKPI_MainOMSView.dbPatID,
ReferralKPI_MainOMSView.dbPatLastName,
ReferralKPI_MainOMSView.dbAddDate,
ReferralKPI_MainOMSView.LastName,
ReferralKPI_MainOMSView.dbStaffLastName
From ReferralKPI_MainOMSView
Where (ReferralKPI_MainOMSView.dbAddDate <= '2013 Apr')
AND (ReferralKPI_MainOMSView.dbStaffLastName IN ('') OR '' = '')
AND (ReferralKPI_MainOMSView.LastName IN ('Hameed') OR 'Hameed' = '')


where the date is passed through in that format YYYY MMM ( I think as a string but maybe a datetime type)

the dbAddDate is in the typical datetime format yyyy-mm-dd hh:mm:ss

and surprisingly it almost works, it brings back all rows who's date is LESS than 2013 Apr BUT not equal to Apr and in fact that's all I want, rows that are EQUAL to, in this case 2013 Apr.

I tried just dropping the '<' part of the operator but it doesn't bring back any rows.

with my limited sql knowledge I'm stumped.

thanks

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2013-09-16 : 00:05:04
[code]
Where (ReferralKPI_MainOMSView.dbAddDate < dateadd(month, 1, convert(datetime, '2013 Apr'))
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -