日期查询
2008-01
2008-05
2008-10
2008-12
以上是字符类型
把显示的年份用sql server写成上一个月的日期
[解决办法]
SELECT DATEDIFF(month, -1, Col1 + '-01') FROM TABLE1
[解决办法]
--> 测试数据: @Tdeclare @T table (dt varchar(7))insert into @Tselect '2008-01' union allselect '2008-05' union allselect '2008-10' union allselect '2008-12'select dt,convert(varchar(7),dateadd(month,-1,dt+'-01'),120) predtfrom @T/*dt predt------- -------2008-01 2007-122008-05 2008-042008-10 2008-092008-12 2008-11(4 row(s) affected)*/