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()?
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" ;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With