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
 General SQL Server Forums
 New to SQL Server Programming
 Help with SQL query

Author  Topic 

ironmonkey
Starting Member

8 Posts

Posted - 2010-10-13 : 17:47:53
I have a table that contains a date column (type date), and I want to return all rows but if the date = 1900-01-01, I want it to display NULL or blank. But if it is any other date return the date value.

This is what I have so far? Perhaps there is a better way of doing this? I'm getting the following error

"Conversion failed when converting date and/or time from character string."


Select FirstName, LastName, Salary,
CASE CAST(StartDate as CHAR)
When '1900-01-01' Then 'NULL'
Else StartDate
END
From HR_test


Thanks for the help!!

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-10-13 : 17:53:43
Select FirstName, LastName, Salary,
CASE StartDate
When '1900-01-01' Then NULL
Else StartDate
END
From HR_test

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

ironmonkey
Starting Member

8 Posts

Posted - 2010-10-13 : 18:01:31
That worked. Thanks very much tkizer!!!
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-10-13 : 18:07:40
You're welcome, glad to help.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2010-10-13 : 21:02:51
WHEN 0 THEN null ELSE Startdate END

In any case...add a constraint <> 0

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx





Go to Top of Page
   

- Advertisement -