请问 怎么select 某年某月的 相关信息?应该怎么写?我的date列是 2007-01-02 上午 10:00:00 这种形式的
select id,content from art where date???????
 
我只想 select 精确到月份
select id,content from art where date='2007-01' 这样不行把? 应该怎么写呢?

解决方案 »

  1.   

    select id,content from art where convert(char(7),date,120)='2007-01'
      

  2.   

    如果date是字符型的话select id,content from art where left(date,7)='2007-01'
      

  3.   

    select id,content from art where date>='2007-1-1' and date <'2007-2-1'这样速度快些
      

  4.   

    请问为什么说我的 convert 函数未定义呢?
      

  5.   

    你的语句是怎样写的?
    还有dateg列是什么类型的?
      

  6.   

    还有date列是什么类型的?
      

  7.   

    类型就是 日期/时间  
    Dim str3 As String = " select * from art where convert(char(7),date,120)='" + yearstr + "-" + monthstr + "'"
    这样写的  
    说 convert 函数未定义
      

  8.   

    我习惯用DATEDIFF ( datepart , startdate , enddate )比如:选择 datecol 列值等于 2007-01-02 的行SELECT * FROM TALBE WHERE DATEDIFF(day,datecol,'2007-01-02')=0;
      

  9.   

    select * from table where year(date)+month(date)='20071'
      

  10.   

    为什么说我的 convert 函数未定义呢?
      

  11.   

    Dim str3 As String = " select * from art where convert(char(7),date,120)=''" + yearstr + "-" + monthstr + "''"
      

  12.   

    sql中用两个单引号表示一个单引号.
    还会出错吗?
    本人不懂VB
      

  13.   

    select * from table where convert(varchar(4),date)+convert(varchar(2),date)='20073'
      

  14.   

    select id,content from art where date like '2007-01%'
      

  15.   

    select id,content from art where convert(char(7),date,120)='2007-01'   联机帮助上有详细的讲解
      

  16.   

    Dim str3 As String = "select * from art where date like '" + yearstr + "-" + monthstr + "%'"  最后这样写通过了  谢谢大家
      

  17.   

    neo_aksa() ( ) 信誉:100    Blog  2007-04-02 13:42:15  得分: 0  
     
     
       select * from table where year(date)+month(date)='20071'
      
     
    -------------------------------------------------
    比如date是'2007-04-02',你的结果会是2011,需要转为字符型再连接
    select * from [table] where rtrim(year(date))+rtrim(month(date))='20071'
     neo_aksa() ( ) 信誉:100    Blog  2007-04-02 14:20:19  得分: 0  
     
     
       select * from table where convert(varchar(4),date)+convert(varchar(2),date)='20073'
      
    ---------------------------------------------------
    也不对 hxd001_810(寒冬) ( ) 信誉:100    Blog  2007-04-02 14:22:05  得分: 0  
     
     
       select id,content from art where date like '2007-01%'
      
    --------------------------------------------------------------
    对日期型数据like不对
    select id,content from art where convert(char(10),date,120) like '2007-01%'
      

  18.   

    select id,content from art where convert(varchar(6),date,112)='200701'
      

  19.   

    select id,content from art where date between '2007-01-01' and '2007-01-31'