Wednesday, 21 August 2013

sql Cast when datetime column null or empty

sql Cast when datetime column null or empty

like to cast regdate col as datetime when regdate column not null or empty
and regdate older than 2 years.if it is empty I like to insert regdate as
1900-01-01.
id name regdate
555 bob 24/06/2013 00:00:00
556 tom 24/07/2013 00:00:00
557 jack 24/10/2008 00:00:00
558 susan 24/11/2009 00:00:00
559 emily
560 Mert
SELECT *, CAST(idate AS DATETIME) AS finalDate
INTO #tempFinal
FROM #tempA
WHERE CAST(idate AS DATETIME) < DATEADD(YEAR, -2, GETDATE())
OR idate IS NULL OR idate = ''

No comments:

Post a Comment