Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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:38am
Edited 1-Jun-12 11:11am
Maciej Los142.3K
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

write below query
 
Set dateformat dmy
 
select * from Inscription where datePreInscription >convert(datetime,'31-5-2012')
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Try this:
DECLARE @sDate VARCHAR(10)
 
SET @sDate = '2012-05-31'
 
SELECT * 
FROM Inscription
WHERE datePreInscription = @sDate
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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 at 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 at 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)



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

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100