A table contains a field of type smalldatetimeThe feed has this field as string i.e. '060830'Would like to insert this string date into the field of the table which has a datatype of smalldatetime.
Is this the correct way to convert a string to smalldatetime?
declare @DateFeed varchar(6)declare @TradeDate smalldatetime
set @DateFeed = '060830'
set @TradeDate = convert(smalldatetime, 6 + '-' + 8 + '-' + 30)print @TradeDate
Use function CONVERT, with style 12. Let SQL Server decides the century (0 - 49 --> 2000 / 50 - 99 --> 1900).
Use the following query...
Prefixing the century value on your data & casting the result as datetime
Select Cast('20' + '060830' as smalldatetime)
Microsoft is conducting an online survey to understand your opinion of the Technet Web site. If you choose to participate, the online survey will be presented to you when you leave the Technet Web site.
Would you like to participate?