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)
 Simple SELECT using CASE

Author  Topic 

cullyK
Starting Member

5 Posts

Posted - 2007-02-06 : 04:29:32
I want to create a select statement that that will display 'NA' when recFD is '01/01/1900' otherwise it will display the date stored

Select recSD, recFD = CASE recFD WHEN '01/01/1900' THEN 'NA' ELSE recFD END, recFD From Table 1

This works fine when I run,

Select recSD, recFD = CASE recFD WHEN '01/01/1900' THEN 'NA' END, recFD From Table 1

without the Else recFD but i need to display the recFD if it is not '01/01/1900'

Thanks in advance for your help

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-02-06 : 04:35:19
SELECT recSD, CASE WHEN recFD <= '19000101' OR recFD IS NULL THEN 'NA' ELSE CONVERT(VARCHAR, recFD, 103) END
FROM Table1

You can't mix datatypes in same column. Either convert 'NA' as date (not possible), or convert the date as string.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

cullyK
Starting Member

5 Posts

Posted - 2007-02-06 : 04:39:47
That works perfect thank you
Go to Top of Page
   

- Advertisement -