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)
 NULL Dates

Author  Topic 

LOOKUP_BI
Constraint Violating Yak Guru

295 Posts

Posted - 2011-04-20 : 17:04:41
Is there a way to replace NULL to a datetime column instead of 1900-01-01 00:00:00.000 for NULL dates ?

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-04-20 : 17:30:26
I'm not clear what you mean. Here's 2 solutions based on my poor interpretation:

SELECT NULLIF(DateCol, 0) FROM myTable -- if DateCol = 1/1/1900, replace it with NULL
SELECT IsNull(DateCol, '1/1/1900') FROM myTable -- if DateCol IS NULL, replace it with 1/1/1900

Go to Top of Page

LOOKUP_BI
Constraint Violating Yak Guru

295 Posts

Posted - 2011-04-20 : 17:37:43
Robvolk,you interpreted me correct, let me try this
Go to Top of Page

LOOKUP_BI
Constraint Violating Yak Guru

295 Posts

Posted - 2011-04-21 : 14:12:20
NULLIF worked perfectly for me. Thanks
Go to Top of Page
   

- Advertisement -