0

There are values there for the 3 fields that make up the date here, but I get null back..so something is wrong with my syntax. I also want just the date (no time) `

   case when isdate(CAST(someTable.DATE_MM as varchar(8)) + CAST(someTable.DATE_DD as varchar(8)) + CAST (someTable.DATE_YY as varchar(8))) = 1
        then convert(date,CAST(someTable.DATE_MM as varchar(8)) + '/' + CAST(someTable.DATE_DD as varchar(8)) + '/' + CAST (someTable.DATE_YY as varchar(8))) else null end as BirthDate,

that's in my select statement and it's giving me NULL for the data. The values for those 3 fields are:

DATE_MM: 3
DATE_DD: 4
DATE_YY: 1959

the data type behind those 3 fields is int

2 Answers2

0

You merge 3 varchar values together, it will return a varchar, therefore your isdate will return false and your case will return the null value from the else clause.

Hugo V
  • 184
  • 3
  • well then how do I combine them together. I don't want to do int + int+ int ...that's adding, not appending the parts together to make a date so that the convert will work. So I'm doing it via varchar so I can append those together... – user1808194 Nov 08 '12 at 16:42
0

You could do it with dateadd instead.

select dateadd(day, DATE_DD - 1, 
               dateadd(month, DATE_MM - 1, 
                       dateadd(year,  DATE_YY - 1900, 0))) as BirthDate
from someTable
Mikael Eriksson
  • 136,425
  • 22
  • 210
  • 281