views:

254

answers:

4

I am moving data from one table to another and I want a date field to change from null to a default value. What is the best way to do this in SQL Server(2000) ?

I want something similar to the IIf function in Access. Like IIF(DateBegin is null, #1/1/2000#,DateBegin)

A: 

Use the ISNULL operator.

JG
A: 

You can use coalesce to do this.

JP Alioto
+3  A: 
INSERT INTO destTable (dateColumn, otherColumn)
SELECT ISNULL(dateColumn, '2000-01-01'), otherColumn
FROM sourceTable
Gary McGill
A: 

You could use the COALESCE operator in your select statement:

SELECT ..., COALESCE(datecolumn, 'default date') FROM SOURCE_TABLE

It returns the first non-null value.

M4N