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
 Get pass due tickets

Author  Topic 

scantoria
Starting Member

15 Posts

Posted - 2009-12-29 : 17:44:45
How do I get the tickets where due date is < now.

SELECT COUNT(id) AS PassDueCount, [Due Date]
FROM vwTickets
WHERE ([Due Date] < "todays date")



Stephen Cantoria
scantoria@msn.com

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2009-12-29 : 19:00:56
SELECT COUNT(id) AS PassDueCount, [Due Date]
FROM vwTickets
WHERE ([Due Date] < DATEADD(d,datediff(d,0,getdate()),0)

Jim




Everyday I learn something that somebody else already knew
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2009-12-30 : 04:08:35
Addendum:

jimf's posted method gets everything from before the start of "today" so from all day yesterday and before. The DATEADD portion strips the time information from the GETDATE() function.

If you wanted to get tickets from before now then you just need
WHERE
[Due Date] < GETDATE()


Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page

scantoria
Starting Member

15 Posts

Posted - 2010-01-07 : 14:04:21
Thank you so much! This is very helpful.

Steve


quote:
Originally posted by jimf

SELECT COUNT(id) AS PassDueCount, [Due Date]
FROM vwTickets
WHERE ([Due Date] < DATEADD(d,datediff(d,0,getdate()),0)

Jim




Everyday I learn something that somebody else already knew



Stephen Cantoria
scantoria@msn.com
Go to Top of Page

scantoria
Starting Member

15 Posts

Posted - 2010-01-07 : 14:05:09
Thank you so much! This is very helpful and thank you for explaning the syntax.

Steve



quote:
Originally posted by Transact Charlie

Addendum:

jimf's posted method gets everything from before the start of "today" so from all day yesterday and before. The DATEADD portion strips the time information from the GETDATE() function.

If you wanted to get tickets from before now then you just need
WHERE
[Due Date] < GETDATE()


Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION




Stephen Cantoria
scantoria@msn.com
Go to Top of Page
   

- Advertisement -