首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

求SQL,该如何处理

2012-07-29 
求SQL数据库日期类型为int数据格式为CreateTime2012070520120715如何查询今日,昨日,本月,上月,今年,去年的

求SQL
数据库日期类型为int 
数据格式为
CreateTime
20120705
20120715

如何查询今日,昨日,本月,上月,今年,去年的数据


[解决办法]

SQL code
--今天select * from t where     CreateTime=convert(varchar(8),getdate(),112);--昨天select * from t where     CreateTime=convert(varchar(8),getdate()-1,112);--本月select * from t where     substring(convert(varchar(8),CreateTime),1,6)=convert(varchar(6),getdate(),112);--上月select * from t where     substring(convert(varchar(8),CreateTime),1,6)=convert(varchar(6),dateadd(m,-1,getdate()),112);--今年select * from t where     substring(convert(varchar(8),CreateTime),1,4)=convert(varchar(4),getdate(),112);--去年select * from t where     substring(convert(varchar(8),CreateTime),1,4)=convert(varchar(4),dateadd(year,-1,getdate()),112); 

热点排行