Click here to Skip to main content
15,034,432 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When i write the following sql query under sql server 2008, i get a syntax error. the query aim to retrieve ll the inscriptions that have a 'datePreInscription'(which has a datetime type)column superior to 2012-05-31 12:00:00.000
SQL
select * from Inscription where datePreInscription > 2012-05-31 12:00:00.000
Posted
Updated 3-Jan-18 20:17pm
v2

write below query

SQL
Set dateformat dmy

select * from Inscription where datePreInscription >convert(datetime,'31-5-2012')
   
v2
Try this:
SQL
DECLARE @sDate VARCHAR(10)

SET @sDate = '2012-05-31'

SELECT * 
FROM Inscription
WHERE datePreInscription = @sDate
   
Look at the MSDN article [^]about Cast and Convert.

SQL
SELECT * FROM Inscription WHERE datePreInscription > CONVERT(DateTime, '2012-05-31 12:00:00.000')
   
Comments
elidrissi.amine1 2-Jun-12 7:13am
   
this is the error message i get:
Msg 242, Level 16, State 3, Line 1 The conversion of a varchar data type to data type datetime created value out of range.
Member 10319449 24-Oct-13 7:46am
   
Check the date format.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900