CJSmith dot me

I dump stuff I find useful here

Use a case to make sure provided data is a date

Published / by Chris Smith / Leave a Comment

I find this useful for using validating spreadsheet imports, using ISDATE can just blank the field if crap data is provided

--Use Case to make sure a data field is a date
--Will Work and produce the inserted field
select CASE WHEN ISDATE(t1.datefield) =1 THEN t1.datefield ELSE '' END  as datefield_full
from (select '14/12/2054' as datefield) t1
--Won't Work and will produce Blank
select CASE WHEN ISDATE(t1.datefield) =1 THEN t1.datefield ELSE '' END  as datefield_full
from (select '14/122054' as datefield) t1

Leave a Reply