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.
Author |
Topic |
sz1
Aged Yak Warrior
555 Posts |
Posted - 2014-06-03 : 05:29:31
|
Guys,Anyone tell me why this doesn't work? I want to return todays calls that are closed without having to change the dates all the time using a between clause. declare @mydate date Set @mydate = GETDATE()select ItemNumberFrom dbo.Itemwhere Status = 'Closed'and convert(date,CreatedDateTime) = @mydateThis works by doing a between but why doesn't the @mydate read the getdate() is today from the createddatetime field?ThanksAnd CreatedDateTime between '2014-06-02 00:00:00' and '2014-06-02 23:59:59'We are the creators of our own reality! |
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2014-06-03 : 05:43:29
|
run your working select and add the following columns to your select list.then you can see if they are equal or not.select ItemNumber,@mydate as mydate, convert(date,CreatedDateTime) as CreatedDateTime_convertedFrom dbo.Itemwhere Status = 'Closed'and CreatedDateTime between '2014-06-03 00:00:00' and '2014-06-03 23:59:59' Too old to Rock'n'Roll too young to die. |
|
|
sz1
Aged Yak Warrior
555 Posts |
Posted - 2014-06-03 : 06:39:11
|
It did work after all there were none but 2 have come in now, your query helped me though to look again and I see why you did it that way.Thanks :)declare @mydate date Set @mydate = GETDATE()select ItemNumber, @mydate 'IsToday'From dbo.Itemwhere Status = 'Closed'and convert(date,CreatedDateTime) = @mydateWe are the creators of our own reality! |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2014-06-03 : 08:02:45
|
[code]AND CreatedDateTime >= '20140602'AND CreatedDateTime < '20140603'[/code] Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA |
|
|
sz1
Aged Yak Warrior
555 Posts |
Posted - 2014-06-03 : 08:25:48
|
yep cool got that one,thanksWe are the creators of our own reality! |
|
|
|
|
|
|
|