Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 returning different datatypes in a single column

Author  Topic 

robnot
Starting Member

3 Posts

Posted - 2007-08-08 : 14:47:26
I'm trying to use the following statement, meaning to return a string message if a date field is null.

, coalesce(adr.date_destroyed, 'Not Destroyed')


I get an error message - Syntax error converting datetime from character string - and I'm not sure how to get around this. Is there a way I can disregard the type of the column and get the result I need? Is there a different way of going about this?

Thanks,
Rob

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2007-08-08 : 14:49:56
Tried with isnull function?
Go to Top of Page

robnot
Starting Member

3 Posts

Posted - 2007-08-08 : 15:14:28
I've tried isnull and also a case statement to handle the whole thing. They all have the same result.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-08-08 : 15:24:48
You'll need to convert the column to varchar then run the function. This is because 'Not Destroyed' is not a valid date/time.

coalesce(convert(varchar(50), adr.date_destroyed, 'Not Destroyed')

Tara Kizer
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

robnot
Starting Member

3 Posts

Posted - 2007-08-08 : 15:47:39
That did the trick, thanks so much!
Go to Top of Page
   

- Advertisement -