April 15, 2012 at 12:40 am
Hi
i have this line in my store procedure:
select * from MainVideo where LEFT (datetime,11)=LEFT (@VarDateTime,11)
but the problem is : datetimeis like this : 2012-03-12
but @VarDateTime is like this : 13/03/2012
so i can not compare these two
would you please help me?
April 15, 2012 at 6:14 am
select * from MainVideo where CONVERT(date,datetime) = Convert(date,@VarDateTime,101)
The additional 101paramater is the style, in this case US .
Look at http://msdn.microsoft.com/en-us/library/ms187928(v=sql.105).aspx for additional styles/
April 15, 2012 at 6:17 am
stevro (4/15/2012)
select * from MainVideo where CONVERT(date,datetime) = Convert(date,@VarDateTime,101)The additional 101paramater is the style, in this case US .
Look at http://msdn.microsoft.com/en-us/library/ms187928(v=sql.105).aspx for additional styles/
Correction I see it is style 103(British).
It should be:
select * from MainVideo where CONVERT(date,datetime) = Convert(date,@VarDateTime,103)
April 15, 2012 at 8:16 am
On SQL Server 2008 - I would recommend using CAST({value} AS DATE) instead. This has been optimized so it can still use index seeks where possible and will still use the DATE data type instead of character which would be slower.
Select mv.* -- don't use * in your actual code
From MainVideo mv
Where CAST(mv.[date] AS DATE) = @VarDate
I would also not set the variable to a datetime data type - define it as DATE so you don't have an extra cast in the code.
Jeffrey Williams
“We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”
― Charles R. Swindoll
How to post questions to get better answers faster
Managing Transaction Logs
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply