views:

3212

answers:

1

I was reviewing some SQL queries and I saw a select statement that looked like this

SELECT *
FROM dbo.mytable
WHERE (dbo.mytable.[Date] < { fn NOW() })

What is the purpose of using a WHERE statement like this?

Wouldn't be easier to use a simple GETDATE()?

+10  A: 

http://www.sqlservercentral.com/Forums/Topic183904-8-1.aspx

GETDATE() is a T-SQL specific function which returns the current system date and time. The SQL standard equivalent is CURRENT_TIMESTAMP which is applicable in T-SQL as well. The {fn Now()} is an ODBC canonical function which can be used in T-SQL since the OLE DB provider for SQL Server supports them. There are no notable performance difference between these though. You can also use canonical format like :

SELECT {fn CURRENT_TIMESTAMP()} AS "date & time",
       {fn CURRENT_DATE()} AS "date only",
       {fn CURRENT_TIME()} AS "time only" ;
Jason Lepack
I can't access to the mentionned article. It ask me to log in.
Pascal Paradis
Sign up, it's free. The relevant part is what I posted in my post here.
Jason Lepack