例如取得本月我在csdn里面发表的留言数。
数据表和字段随便举例就行了。

解决方案 »

  1.   

    select * from tablename where year(datecol)=year(getdate()) and month(datecol)=month(getdate())
    --or
    select * from tablename where left(datecol,7)=left(getdate(),7)
      

  2.   

    用第一个的时候出现
    服务器: 消息 241,级别 16,状态 1,行 1
    从字符串转换为 datetime 时发生语法错误。我的时间类型里面数据有
    2004年1月1日
    也有2004-01-01
    这样的。问题是不是出在这里啊?
      

  3.   

    你用的是什么数据库呀?datecol为字符型还是datetime型:
    那你就用left取左边的吧
      

  4.   

    datetime型的,取左边的也不行啊,数据很多很乱啊。
    有些是04月的,有些又是4月或者-04     -4