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 |
|
glilley
Starting Member
10 Posts |
Posted - 2011-01-27 : 16:49:18
|
| I have a table field SO_DateTimeStamp, datatype = datetime, and I want to pull data from that table where the SO_DateTimeStamp is 14 minutes or more earlier than current date/time Now(). In MS Access it would look something like "HAVING (dbo.TABLE.SO_DateTimeStamp < DateAdd("n",-14,Now())". What would it look like in T-SQL? Thanks! |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2011-01-27 : 16:59:32
|
| WHERE dbo.TABLE.SO_DateTimeStamp < DateAdd(minute,-14,GETDATE())Don't put that in the HAVING clause, it will reduce performance (significantly). |
 |
|
|
glilley
Starting Member
10 Posts |
Posted - 2011-01-28 : 07:41:59
|
| Thanks Rob! |
 |
|
|
glilley
Starting Member
10 Posts |
Posted - 2011-01-28 : 08:14:06
|
| Hmmm...Tried this in a view and the result set returns ALL records going back to 5/3/2010:SELECT SO_Number, SO_ReleaseNo, SO_ItemNo, SO_Qty, SO_DateTimeStampFROM dbo.MAS_SO_InvoiceWHERE (SO_DateTimeStamp < DATEADD([minute], - 14, GETDATE()))Tried replacing GETDATE() with Now() and SQL changes syntax to read: < DATEADD([minute], - 14, { fn NOW() }), which still returns all records. |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2011-01-28 : 08:29:54
|
quote: result set returns ALL records going back to 5/3/2010
And this is correct, because they are "14 minutes or more earlier". No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2011-01-28 : 08:39:53
|
| Seems you really meant "later"? So change the < to >=:) |
 |
|
|
glilley
Starting Member
10 Posts |
Posted - 2011-01-28 : 09:00:48
|
| Yep, works fine if I ensure that I exclude rows that have already been marked as invoiced!! Thanks all. |
 |
|
|
|
|
|
|
|