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

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -