question

artistlover avatar image
artistlover asked

date convert help

Item Key Quantity Received Date GELL7443BP2 67 011817 GELL7443BP2 48 020217 GELL7443BP2 6 021717 need to insert into table making recedived date a date not nvarchar(255) insert into [dbo].[y] ( [Item_Key] ,[ID] ,[Unit_Qty] ,[Received_Date] ) select [Item Key] ,'F' ,[Quantity Received] ,CONVERT(nvarchar(255),date,111) from x.dbo.[a-PO-Master] conversion of n varchar resulted in out of range.
date
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

thejamie avatar image
thejamie answered
Looks like only a year followed by a month. Try @date would look like '201717'+ '01' Declare @date date=CONVERT(char(8),@date,112)
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Ken 2 avatar image
Ken 2 answered
try this... declare @date varchar(8) set @date = '020217' select cast(substring(@Date,1,2) +'-'+substring(@Date,3,2) +'-20'+substring(@Date,5,2) as datetime) I avoid nvarchar , unless your dealing with an application that is multiple languages, I fail to see the need.
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

artistlover avatar image artistlover commented ·
The data coming to me is from a "home made" source and it is not clean. I'm trying to get it to correct format. I have tried everything I can find. It might change 25% of dates but not the other 75%. It has to be possible.
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.