sql - Convert INT data type into DateTime Format -
//this script
select case when ipaid_dt>= 1 convert(datetime, convert(char(8),ipaid_dt)) else '' end [transaction date] mytable //my output is
1900-01-01 00:00:00.000 2012-11-11 00:00:00.000 2012-10-26 00:00:00.000 //expected output:
2012-11-11 00:00:00.000 2012-10-26 00:00:00.000 //the 1900-01-01 output should '' only, correct script? note: ipaid_dt int 0 default value.
you're mixing field types , sql server converting '' datetime you. try this:
select case when ipaid_dt > 0 convert(nvarchar(23), convert(datetime, convert(char(8),ipaid_dt))) else '' end [transaction date] mytable
Comments
Post a Comment