34,593
社区成员
发帖
与我相关
我的任务
分享
select replace(convert(char(7),getdate(),120),'-0','-')
/*
-----------
2008-4
*/
--栏位的日期是 2008-10-10 这样的格式,但我想以年月为条件的查询应怎么设?
--如 只想要 2008-2 这样不要日的。谢谢! where Tdate='2008-2' ????? 谢谢!
select convert(char(7),getdate(),120)
select cast(year(getdate()) as char(4))+'-'+cast(month(getdate()) as varchar(2))
/*
-------
2008-04
(所影响的行数为 1 行)
-------
2008-4
(所影响的行数为 1 行)
*/
或者
select * from tab
where datediff(mm,Tdate,'2008-02')=0
select * from tab
where convert(varchar(7),Tdate,120)='2008-02'