Bob Bender
asked on
SQL DATE Problem
Hello Experts,
Got a SQL Server table and have a "Datetime" field that I want to be use in a Select statement with only a "Date" check.
I am on the fence about using either a Cast or Convert.
Select * from tblName
WHERE CAST(date, HireDate) = '2005-03-19"
OR
Select * from tblName
WHERE CONVERT(date, HireDate) = '2005-03-19"
Date gives me yyyy-mm-dd format for the comparison against the HireDate.
What is the real difference between the two and which is needed here? I say CAST, as it only applies to the Select and change/convert anything (whatever it is)
Bob
Got a SQL Server table and have a "Datetime" field that I want to be use in a Select statement with only a "Date" check.
I am on the fence about using either a Cast or Convert.
Select * from tblName
WHERE CAST(date, HireDate) = '2005-03-19"
OR
Select * from tblName
WHERE CONVERT(date, HireDate) = '2005-03-19"
Date gives me yyyy-mm-dd format for the comparison against the HireDate.
What is the real difference between the two and which is needed here? I say CAST, as it only applies to the Select and change/convert anything (whatever it is)
Bob
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
CONVERT is SQL Server specific and CAST is ANSII.. if that helps any.
ASKER
Still odd that both basically do the same thing. I would think using cast would be better, as there are NO decimals places or accuracy needed cause it is a datetime field