200字范文,内容丰富有趣,生活中的好帮手!
200字范文 > server sql 查询一段时间数据语句

server sql 查询一段时间数据语句

时间:2020-07-27 07:19:09

相关推荐

server sql 查询一段时间数据语句

最近七天

select * from tb where 时间字段 = convert(varchar(10),getdate() - 7,120)

随后七天

select * from tb where 时间字段 = convert(varchar(10),getdate() + 7,120) and 时间字段 = 时间字段

上月

select * from tb where month(时间字段) = month(getdate()) - 1

本月

select * from tb where month(时间字段) = month(getdate())

下月

select * from tb where month(时间字段) = month(getdate()) + 1

--昨天

Select * From TableName Where DateDiff(dd, DateTimCol, GetDate()) = 1

--明天

Select * From TableName Where DateDiff(dd, GetDate(), DateTimCol) = 1

--最近七天

Select * From TableName Where DateDiff(dd, DateTimCol, GetDate()) = 7

--随后七天

Select * From TableName Where DateDiff(dd, GetDate(), DateTimCol) = 7

--上周

Select * From TableName Where DateDiff(wk, DateTimCol, GetDate()) = 1

--本周

Select * From TableName Where DateDiff(wk, DateTimCol, GetDate()) = 0

--下周

Select * From TableName Where DateDiff(wk, GetDate(), DateTimCol ) = 1

--上月

Select * From TableName Where DateDiff(mm, DateTimCol, GetDate()) = 1

--本月

Select * From TableName Where DateDiff(mm, DateTimCol, GetDate()) = 0

--下月

Select * From TableName Where DateDiff(mm, GetDate(), DateTimCol ) = 1

--------------------------------------------------------

本周

select * from tb where datediff(week , 时间字段 ,getdate()) = 0

上周

select * from tb where datediff(week , 时间字段 ,getdate()) = 1

下周

select * from tb where datediff(week , 时间字段 ,getdate()) = -1

纯数字时间这样转换

and datediff(mm,GETDATE(),convert(DATETIME,CONVERT(NVARCHAR,

substring(CONVERT(varchar(100),YL01),0,9),20))) =3

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。