Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check multiple columns for null in SQL Server 2008

Table A:

Id  Name  DateCreated  DateModified
-----------------------------------
1    A     2013-1-12    2013-1-15
2    B     NULL         2013-2-1
3    C     NULL          NULL

I have to migrate this table's data to another table in which DateCreated is a not nullable column, and the conditions are if DateCreated is null use DateModified and if both are null use current date.

I can't use

ISNull(DateCreated,DateModified)

because both can be null.

How do I do it? The table has around 10000 rows.

like image 228
Infant Dev Avatar asked Jan 14 '23 02:01

Infant Dev


1 Answers

You can use COALESCE(DateCreated, DateModified, GETDATE())

like image 168
Sergio Avatar answered Jan 17 '23 04:01

Sergio