Salman Arshad
Salman Arshad

Reputation: 272006

Dealing with SQL server datetime edge cases

I have the following data in a SQL Server 2000 table:

Dates
-----------------------
2012-05-04 01:23:45.678
2012-05-05 01:23:45.678
2012-05-06 01:23:45.678

Suppose GETDATE() returns:

2012-05-05 12:34:56.789

I need the most efficient (and elegant) query that returns rows #2 and #3 from above, the criteria being:

date portion of Dates >= date portion of GETDATE()

Upvotes: 0

Views: 361

Answers (1)

Oded
Oded

Reputation: 498904

DECLARE @Now DATETIME
SELECT @Now = DATEADD(dd, DATEDIFF(dd, 0, GETDATE()), 0)

SELECT ...
WHERE Dates >= @Now 

Adapted from this and this.

Upvotes: 4

Related Questions