现在数据表里有一个日期型的字段,让我给拼写成了convert(nvarchar(32),year(时间))+'年'+convert(nvarchar(32),month(时间))+'月'+convert(nvarchar(32),day(时间))+'日' as 时间select出来的数据就是
时间
2011年1月1日
2011年2月1日
2011年2月1日
2011年3月1日
2011年4月1日
2011年1月1日
2011年1月1日现在想模糊查询
select 时间 from 表 where 时间 like '%2011年1月%'
这样怎么查不出来数据了呢
得到的结果是
2011年1月1日
2011年1月1日
2011年1月1日

解决方案 »

  1.   

    select 时间 from 表 where 时间 like '%2011年[1-4]月%'查1~4月 ?
      

  2.   

    select 时间 from 表 where CONVERT(VARCHAR(7),时间,120)='2010-01'--datetime類型這樣用
      

  3.   

    select 时间 from 表 where CONVERT(VARCHAR(7),时间,120)='2011-01'--或
    select 时间 from 表 where CONVERT(VARCHAR(7),时间,112)='201011'
    select 时间 from 表 where DATEDIFF(mm,时间,'20110101')=0
      

  4.   

    select 时间 from tb where CONVERT(VARCHAR(7),时间,120)='2011-01'
      

  5.   

    select convert(nvarchar(32),year(时间))+'年'+convert(nvarchar(32),month(时间))+'月' as 时间 from tb where convert(varchar(7),时间,120)='2011-01'