Re: Format a datetime columns output?
- From: Erland Sommarskog <esquel@xxxxxxxxxxxxx>
- Date: Thu, 8 Jun 2006 07:02:49 +0000 (UTC)
CK (c_kettenbach@xxxxxxxxxxx) 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@xxxxxxxxxxxxx
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
.
- References:
- Format a datetime columns output?
- From: CK
- Re: Format a datetime columns output?
- From: Erland Sommarskog
- Re: Format a datetime columns output?
- From: CK
- Format a datetime columns output?
- Prev by Date: Re: Format a datetime columns output?
- Next by Date: SQL Server + Oracle Data linked in one query
- Previous by thread: Re: Format a datetime columns output?
- Next by thread: Re: Format a datetime columns output?
- Index(es):
Relevant Pages
|