to 空空大师: 应为char(7) CONVERT (char(7), StartTime, 20)='2002-05' StartTime>='2002-05-1' and StartTime<'2002-06-01'
比如一个数据表中其中有个字段是日期型StartTime 有一条记录的值为2002-6-28 12:00:00 用SQL语句查询出2002年5月的所有记录, select * from User where to_char(startTime,'YYYY-MM-DD HH24:MI:SS')>'2002-6-22 00:00:00'
last week: where datepart(ww,StartTime)=datepart(ww,getdate())-1
select * from User where to_char(startTime,'YYYY-MM-DD HH24:MI:SS')>'2002-6-22 00:00:00' 上周的, sorry
last 1 - 2 weekwhere datepart(ww,StartTime)>=datepart(ww,getdate())-2 and datepart(ww,StartTime)<=datepart(ww,getdate())-1
应为char(7)
CONVERT (char(7), StartTime, 20)='2002-05'
StartTime>='2002-05-1' and StartTime<'2002-06-01'
有一条记录的值为2002-6-28 12:00:00
用SQL语句查询出2002年5月的所有记录,
select * from User where to_char(startTime,'YYYY-MM-DD HH24:MI:SS')>'2002-6-22 00:00:00'
where datepart(ww,StartTime)=datepart(ww,getdate())-1
上周的, sorry
and datepart(ww,StartTime)<=datepart(ww,getdate())-1