sql - Check if value is date and convert it -
i using sql server 2012
i receive data in format. dates numeric(8,0)
example 20120101 = yyyymmdd
there exists rows values (0,1,2,3,6)
in date field, not date.
i want check if date , convert it, else can null.
now following code works, hoping there better way.
(case when [invoice_date] '________' --there 8 underscores convert(datetime, cast([invoice_date] char(8))) end) invoice_date
any appreciated.
use isdate function ..
(case when isdate (invoice_date) = 1 convert(datetime, cast([invoice_date] char(8))) end) invoice_date
Comments
Post a Comment