From: Erland Sommarskog on
picayunish (nospam(a)nospam.com) writes:
> Instead of using GetData() use GetDate() in the where or in the having.
>
> e.g.
> select *
> from tblOrders
> where datepart(yyyy, tblOrders.DateRec) = datepart(yyyy, getdate())
> and datepart(mm, tblOrders.DateRec) = datepart(mm, getdate())
> and datepart(dd, tblOrders.DateRec) = datepart(dd, getdate())

This is not a very good solution, as it kills any index there may be on the
date column.

--
Erland Sommarskog, SQL Server MVP, esquel(a)sommarskog.se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
SQL 2000: http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx

From: Plamen Ratchev on
Here is a great article from Tibor Karaszi on dealing with date/time
data types and how to query ignoring the time portion:
http://www.karaszi.com/SQLServer/info_datetime.asp#Searching

--
Plamen Ratchev
http://www.SQLStudio.com
First  |  Prev  | 
Pages: 1 2
Prev: For XML Path / used with Pivot
Next: query