从表中取出某年或某月的数据

作者: 浏览: 发布日期:2010-11-03
[导读]:

select * from table1 where month(convert(varchar(10),btime,112))=9    //取出9月的数据

select year(convert(varchar(10),getdate(),120))     //得到当前的年份

select month(convert(varchar(10),btime,120)) from table1   //得到当前表数据的月份

select * from table1 where month(convert(varchar(10),btime,120))=3   //取出3月份的数据

在上面语句中,btime字段需要是日期格式


免责声明:本文来源于网络,版权归原作者所有,仅供大家共同分享学习,如作者认为涉及侵权,请与我们联系,我们核实后立即删除。本站地址:http://www.sjz2.cn/news/show-129.html
请填写下方表单,我们会尽快与您联系
感谢您的咨询,我们会尽快给您回复!