一开始是这样写的:
m_query.Format("select * from PAYOUT where Month([date]) = Month(#%s#) order by date,id asc",strToday);发现查询出的结果只按月,不按年,比如说,查12月的记录,会同时出现2008年12月和2009年12月的记录
现在想要以"2009-12"这种形式进行查询,请问怎么写?

解决方案 »

  1.   


    order by convert(nvarchar(6),日期,120)
      

  2.   

    select * from PAYOUT where convert(varchar(7),[date],120)='2009-12'
      

  3.   

    where year(date)=year(#%s#) and Month([date]) = Month(#%s#) 
      

  4.   

    select * from PAYOUT where to_char([date]) = '2009-12' order by date,id asc
      

  5.   

    m_query.Format("select * from PAYOUT where yeah([date])= year(#%s#) and  Month([date]) = Month(#%s#) order by date,id asc",strToday,strToday); 
      

  6.   

    select * from PAYOUT where to_char([date],'yyyy-mm') = '2009-12' order by date,id asc
    少写了一点,呵呵。
      

  7.   

    select * from PAYOUT where convert(varchar(7),date,120) = '2009-12' order by date,id asc