使用sql server比较两个datetime [英] compare two datetime using sql server
本文介绍了使用sql server比较两个datetime的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我在sql server 2008下编写以下sql查询时,我收到语法错误。查询旨在检索具有'datePreInscription'(具有日期时间类型)列的铭文,该列优于 2012-05-31 12:00:00.000
选择 * 来自铭文 where datePreInscription> 2012-05-31 12:00:00。 000
解决方案
写下面的查询
设置 dateformat dmy
选择 * 来自铭文其中 datePreInscription> convert( datetime ,' < span class =code-string> 31-5-2012')
试试这个:
< pre lang =sql> DECLARE @ sDate VARCHAR ( 10 )
SET @ sDate = ' 2012-05-31'
SELECT *
FROM 铭文
WHERE datePreInscription = @ sDate
查看MSDN 文章 [ ^ ]关于Cast和Convert。
SELECT * FROM 铭文 WHERE datePreInscription> CONVERT ( DateTime ,' 2012-05-31 12:00:00.000')
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
解决方案
write below query
Set dateformat dmy select * from Inscription where datePreInscription >convert(datetime,'31-5-2012')
Try this:
DECLARE @sDate VARCHAR(10) SET @sDate = '2012-05-31' SELECT * FROM Inscription WHERE datePreInscription = @sDate
Look at the MSDN article [^]about Cast and Convert.
SELECT * FROM Inscription WHERE datePreInscription > CONVERT(DateTime, '2012-05-31 12:00:00.000')
这篇关于使用sql server比较两个datetime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文