Click here to Skip to main content
Sign Up to vote bad
good
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
select * from Inscription where datePreInscription > 2012-05-31 12:00:00.000
Posted 1 Jun '12 - 8:38
Edited 1 Jun '12 - 11:11
Maciej Los54.8K


3 solutions

write below query
 
Set dateformat dmy
 
select * from Inscription where datePreInscription >convert(datetime,'31-5-2012')
  Permalink  
Try this:
DECLARE @sDate VARCHAR(10)
 
SET @sDate = '2012-05-31'
 
SELECT * 
FROM Inscription
WHERE datePreInscription = @sDate
  Permalink  
Look at the MSDN article [^]about Cast and Convert.
 
SELECT * FROM Inscription WHERE datePreInscription > CONVERT(DateTime, '2012-05-31 12:00:00.000')
  Permalink  
Comments
elidrissi.amine1 - 2 Jun '12 - 7:13
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.

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 8,123
1 OriginalGriff 6,040
2 CPallini 3,432
3 Rohan Leuva 2,703
4 Maciej Los 2,234


Advertise | Privacy | Mobile
Web01 | 2.6.130516.1 | Last Updated 1 Jun 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid