Click here to Skip to main content
12,445,482 members (61,702 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: SQL-Server DateTime
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
Updated 1-Jun-12 11:11am
Maciej Los225.6K
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 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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160811.3 | Last Updated 1 Jun 2012
Copyright © CodeProject, 1999-2016
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