SSIS to SQL Server data import and conversion issue -
i beginner sql server 2014. need advise data type conversion ssis sql server.
i working datetime
column, example value "2017-08-17 16:00:50" in format 'yyyymmddhhmmsssss'
from ssis have used data type unicode string [dt_wstr]
, in sql server have used data type nvarchar
.
when trying import data ssis, changes date format 2017-08-17 16:00:50 17/08/2017 4:00:50 pm. how prevent , when try , convert varchar date datetime format using cast or convert this:
with convert
select convert(datetime, [lastupdatedatetime], 109) [lastupdatedatetime] mytable
i error:
msg 241, level 16, state 1, line 2
conversion failed when converting date and/or time character string.
with cast
select cast([lastupdatedatetime] datetime) [lastupdatedatetime] mytable
i error:
msg 242, level 16, state 3, line 2
conversion of nvarchar data type datetime data type resulted in out-of-range value.
please advise,
you should use date style 103 in convert
try this:
declare @dt nvarchar(50)=convert(nvarchar(50),[lastupdatedatetime],103) select convert(datetime2(0), @dt, 103)
Comments
Post a Comment