工具/材料:Management Studio。
1、首先在桌面上,点击“Management Studio”图标。
2、之后在该界面中,点击左上角“新建查询”选项。
3、接着在该界面中,输入昨天,今天,明天和本周的记录的sql语句“select * from test2 where time = DATEADD( day,-1, convert(varchar(10),getdate(),120) )select * from test2 where time= DATEADD( day,0, convert(varchar(10),getdate(),120) )select * from test2 where time>DATEADD( day,-6, convert(varchar(10),getdate(),120) )”。
4、然后在该界面中,点击左上方“执行”按钮。
5、最后在该界面中,显示昨天,今天,明天和本周的记录成功。
主要用到sql 函数
DATEDIFF( datepart , startdate , enddate )
startdate=日期字段名称
--查询 今日
select * from tableA where DateDiff(dd,datetime类型字段,getdate())= 0
--查询 昨日
select * from tableA where DateDiff(dd,times,getdate())= 1
--查询 本周
select * from tableA where DateDiff(dd,VoucherDate,getdate())<=7
--查询 上周
select * from tableA where DateDiff(dd,VoucherDate,getdate())>7 and DateDiff(dd,VoucherDate,getdate())<=14
--查询 本月
select * from tableA where DateDiff(mm,VoucherDate,getdate())= 0
--查询 上月
select * from tableA where DateDiff(mm,VoucherDate,getdate())= 1
--查询 本年
select * from tableA where DateDiff(yy,VoucherDate,getdate())= 0
--查询 上一年
select * from tableA where DateDiff(yy,VoucherDate,getdate())= 1
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)