-5
  convert(datetime,  BIRTH_MM + '/' +  BIRTH_DD + '/' + BIRTH_YY, 103) as Birthdate

所以连接的字符串如下所示:04/05/88

试图让这个工作。

试过这个,关闭我现在得到一个日期,但它给了我 1900 年或 1905 年,这是不对的

convert(datetime,  BIRTH_MM + BIRTH_DD + BIRTH_YY, 103) as Birthdate

更新

尝试了一些东西,但还没有:

 case when(BIRTH_DD > 0 and BIRTH_MM > 0 and BIRTH_YY > 0)
    then 
            convert(datetime, cast(BIRTH_DD as varchar(1)) + '/' + cast(_BIRTH_MM as varchar(2)) + '/' + cast(BIRTH_YY as varchar(4)), 103)
    else
            convert(datetime, '1900-01-01', 103) as Birthdate,
        end
4

1 回答 1

2

在没有看到这些值的表结构或数据类型的情况下,您可以使用类似于以下内容的内容:

declare @BIRTH_MM int = 04
declare @BIRTH_DD int = 05
declare @BIRTH_YY int = 1988

select convert(datetime,
               cast(@BIRTH_MM as varchar(2)) + '/' +  
               cast(@BIRTH_DD as varchar(2)) + '/' + 
               cast(@BIRTH_YY as varchar(4)), 101) as Birthdate

SQL Fiddle with Demo

于 2012-10-29T16:54:10.910 回答