views:

37

answers:

2

work on Sql server 2000. i want to get the current server date and time then want to compare it with my table column EntryDate .How to?

Declare @id datetime

Select @id = DATEPART(hour,GETDATE())

SELECT [Name],[BirthDate],[Email]
FROM Customers3 where BirthDate<=@id-1 AND BirthDate>=@id

want to get on the range value like @id=10.I want to get those values whose are between 9 to 10

+3  A: 

Use:

WHERE t.birthdate BETWEEN DATEADD(hh, -1, GETDATE()) AND GETDATE()

Reference: DATEADD

OMG Ponies
A: 

You need to use the query along the DatePart like this:

Declare @id datetime

Select @id = DATEPART(hour,GETDATE())

SELECT [Name],[BirthDate],[Email] FROM Customers3 where DatePart(HOUR,BirthDate) between @id-1 AND @id

jankhana
While that would work, if there were an index on the birthdate column - your query wouldn't use it due to performing a function on the column before the comparison.
OMG Ponies