|
Posted by Erland Sommarskog on 06/08/06 07:02
CK (c_kettenbach@hotmail.com) writes:
> I used , Convert(varchar(25), L.FromDate, 101) AS FromDate in the View
> and then CAST(FromDate AS DateTime)>= '03/27/2004' in the query. This
> is an internal application but I see why it should be done in code.
This looks just wrong to me.
If you have a view, and need a condition on it with >=, why one Earth would
you could convert the date to a string? And why would you convert it to a
string that only works sometimes? When working with dates in literals in
SQL Server you should use the format YYYYMMDD, because this format is always
interpreted the same. Most other format depends on language and date format
settings.
If you are passing dates from the application as parameters, you should use
parameterised statements and pass datetime values as such not as strings.
--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
[Back to original message]
|