Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
This should return 2 as there are 2 events between todays date and the date 12 months befor today. It returns 0. I think the issue is because the column type of EventDate is nchar. Is this correct?
DECLARE @y dateDECLARE @d dateSET @y = DATEADD(m, -12, CURRENT_TIMESTAMP)SET @d = CAST(GETDATE() AS date) SELECT COUNT(*)FROM tbl_HAW_HealthAndSafety_LRIWHERE EventDate BETWEEN @y AND @d
russell
Pyro-ma-ni-yak
5072 Posts
Posted - 2012-04-03 : 12:18:01
WHERE Convert(date, EventDate) BETWEEN @y AND @d
chapm4
Yak Posting Veteran
58 Posts
Posted - 2012-04-03 : 12:30:14
Thanks for the help. Still gives me zero. Any other ideas? I might be wrong on the type.
OK stupidity proven. I hadn't put data in the table after deleting first thing this morning.....is it a weekend yet? The above answer did work. tHANKS SO MUCH FOR THE HELP.
russell
Pyro-ma-ni-yak
5072 Posts
Posted - 2012-04-03 : 16:01:00
LOL. Glad to help
Bustaz Kool
Master Smack Fu Yak Hacker
1834 Posts
Posted - 2012-04-03 : 16:34:03
We've all been there. QED=================================================There is a foolish corner in the brain of the wisest man. -Aristotle, philosopher (384-322 BCE)