SQLʱ¼ä¶Î²éѯ
ACCESSµÄ»°
select * from table where date1<#2008-1-20# and date2>#2007-8-30#
MYSQLµÄ»°
select * from table where date1<'2008-1-20' and date2>'2007-3-30'
Ò²¿ÉÒÔ
select * from table where date1 between '2008-1-20' and '2007-3-30'
ÆäÖÐdate1,date2¶¼ÊÇÈÕÆÚÀàÐ͵Ä×Ö¶Î
sQLʱ¼äÐͲéѯÓï¾ä
2007Äê12ÔÂ04ÈÕ ÐÇÆÚ¶þ 13:54
select * from jy_jjgl a ,jy_jygl b where convert(varchar(10),a.shtime,120)='2007-11-27'
1.ÏÔʾ±¾ÔµÚÒ»Ìì
SELECT DATEADD(mm,DATEDIFF(mm,0,getdate()),0)
select convert(datetime,convert(varchar(8),getdate(),
120)+'01',120)
2.ÏÔʾ±¾ÔÂ×îºóÒ»Ìì
select dateadd(day,-1,convert(datetime,convert
(varchar(8),dateadd(month,1,getdate()),120)+'01',120))
SELECT dateadd(ms,-3,DATEADD(mm,DATEDIFF(m,0,getdate())+1,0))
3.ÉϸöÔµÄ×îºóÒ»Ìì
SELECT dateadd(ms,-3,DATEADD(mm,DATEDIFF(mm,0,getdate()),0))
4.±¾ÔµĵÚÒ»¸öÐÇÆÚÒ»i
select DATEADD(wk,DATEDIFF(wk,0, dateadd(dd,6-datepart(
day,getdate()),getdate())),0)
5.±¾ÄêµÄµÚÒ»Ìì
SELECT DATEADD(yy,DATEDIFF(yy,0,getdate()),0)
6.±¾ÄêµÄ×îºóÒ»Ìì
SELECT dateadd(ms,-3,DATEADD(yy,DATEDIFF(yy,0,getdate())+1,0))
7.È¥ÄêµÄ×îºóÒ»Ìì
SELECT dateadd(ms,-3,DATEADD(yy,DATEDIFF(yy,0,getdate()),0))
8.±¾¼¾¶ÈµÄµÚÒ»Ìì
SELECT DATEADD(qq,DATEDIFF(qq,0,getdate()),0)
9.±¾ÖܵÄÐÇÆÚÒ»
SELECT DATEADD(wk,DATEDIFF(wk,0,getdate()),0)
10.²éѯ±¾ÔµļǼ
select * from tableName where DATEPART(mm, theDate)
=DATEPART(mm, GETDATE()) and DATEPART(yy, theDate)
= DATEPART(yy, GETDATE())
11.²éѯ±¾ÖܵļǼ
select * from tableName where DATEPART(wk, theDate) = DATEPART
(wk, GETDATE()) and DATEPART(yy, theDate) = DATEPART(yy, GETDATE())
12²éѯ±¾¼¾µÄ¼Ç¼ ×¢£ºÆäÖÐ:GETDATE()ÊÇ»ñµÃϵͳʱ¼äµÄº¯Êý¡£
select * from tableName where DATEPART(qq, theDate) = DATEPART
(qq, GETDATE()) and DATEPART(yy, theDate) = DATEPART(yy, GETDATE())
13.»ñÈ¡µ±ÔÂ×ÜÌìÊý:
select DATEDIFF(dd,getdate(),DATEADD
(mm, 1, getdate()))
select datediff(day,
dateadd(mm, datediff(mm,'',getdate()), ''),
dateadd(mm, datediff(mm,'',getdate()), '1900-0
ÁÙʱ±í¾ÍÊÇÄÇЩÃû³ÆÒÔ¾®ºÅ (#) ¿ªÍ·µÄ±í¡£Èç¹ûµ±Óû§¶Ï¿ªÁ¬½ÓʱûÓгýÈ¥ÁÙʱ±í£¬SQL Server ½«×Ô¶¯³ýÈ¥ÁÙʱ±í¡£ÁÙʱ±í²»´æ´¢ÔÚµ±Ç°Êý¾Ý¿âÄÚ£¬¶øÊÇ´æ´¢ÔÚϵͳÊý¾Ý¿â tempdb ÄÚ¡£
ÁÙʱ±íÓÐÁ½ÖÖÀàÐÍ£º
±¾µØÁÙʱ±í
ÒÔÒ»¸ö¾®ºÅ (#) ¿ªÍ·µÄÄÇЩ±íÃû¡£Ö»ÓÐÔÚ´´½¨±¾µØÁÙʱ±íµÄÁ¬½ÓÉϲÅÄÜ¿´µ½ÕâЩ±í£¬Á´½Ó¶Ï¿ªÊ±ÁÙʱ±í¼´±»É¾³ý ......