首先创建数据,类型可以为varchar类型,如图:

创建一个表:
create table Material( ?mid int identity(1,1),? ?createTime varchar(20), ?primary key (mid)?? )
可以进行数据的操作,请看以下:
select * from Material ; insert into Material (createTime) values(convert(varchar(10),getdate(),120)); 1.年的查询 --查询某年???比如查询2011年的数据 select??* from Material where year(createTime)=2011 --查询某年到某年???比如查询2011年到2012年 select??* from Material where year(createTime) between 2011 and 2013
2.月的查询 --查询某月??比如查询2011年11月份数据 select *from??Material where convert(varchar(7),createTime,120)= '2011-11' select??* from Material where year(createTime)=2011 and month(createTime)=10 select * from Material where createTime between datename(year,getdate())+'-10-01' and datename(year,getdate())+'-10-30' --查询某年某月???到??某年某月???比如查询2011年10月到2011年11月的之间的数据() select * from Material where convert(varchar(7),120) between '2011-09' and '2011-10'
3.日的查询 --查询某日??比如查询2011年10月7日的数据 select??* from Material where year(createTime)=2011 and month(createTime)=10 and day(createTime)=7; --查询某年某月某日???到??某年某月某日 select * from Material where createTime between '2011-10-1' and '2011-11-6' select * from Material where createTime between datename(year,getdate())+'-10-1' and datename(year,getdate())+'-11-8'
(编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|