现在我的字段date是char类型。里面的数据如下
2008-2-3
2008-5-10我想用SQL语句把它转换成2008-02-03这种类型的格式。然后再去做比较!
想要的SQL语句是 select date from table where date='2008-02-03' 想让这句话能相等!

解决方案 »

  1.   

    数据库是SQL2000CONVERT(varchar(10) ,'2008-9-2', 120) 
    这句获得的值还是 2008-9-2 不会添加0 
      

  2.   

    select date from table where date=convert(varchar(10),'2008-2-3',120)如果你的字段中值存的有时分秒,只比较日,那么
    select date from table where datediff(dd,date,'2008-2-3')=0
      

  3.   

     select date from table where convert(char(10),date,120)='2008-02-03' 
      

  4.   

    select DATENAME(YEAR,'2008-9-2')+'-'+DATENAME(MONTH,'2008-9-2')+'-0'+DATENAME(DAY,'2008-9-2')
      

  5.   

    select date from table where date=convert(varchar(10),cast('2008-2-3' as datetime),120)
      

  6.   

    where convert(char(10),date,120)='2008-02-03' 
      

  7.   

    解决,谢谢。
    顺便说下 convert(char(10),date,120)  获取的值 不会在前面加0的!
      

  8.   


    select date from table where covert(nvarchar(10),date,120)='2008-02-03'