用cast(day(@theTime) as char(2) 取得当前日期,返回值为1,如何让它返回一个01的字符串,用来生成票据单号的?
比如2006-01-01,如何返回20060101而不是200611

解决方案 »

  1.   

    convert(varchar, @thetime, 112)
      

  2.   

    select convert(char(10),getdate(),112)
      

  3.   

    DECLARE @theTime DATETIME
    SET @theTime='2006-01-01'SELECT @theTimeSELECT CONVERT(VARCHAR,@theTime,112)
      

  4.   

    declare @dt datetime
    set @dt='2006-01-01'
    select convert(nvarchar(8), @dt, 112)
      

  5.   

    select convert(varchar(8),getdate(),112) as todaytoday    
    -------- 
    20061102(所影响的行数为 1 行)