I have searched and tried everything to resolve this issue but no luck. I have a date (Start_Date) in 12/1/2017 format (datatype nvarchar) and I need to convert it to a date 2017-12-01 format in order to compare against another start date that is in 2017-12-01 format.
I tried
UPDATE #temp2
SET [start_date] = CONVERT(NVARCHAR(255), CONVERT(SMALLDATETIME,[start_date], 105))
but I get this error:
Msg 242, Level 16, State 3, Line 1
The conversion of a nvarchar data type to a smalldatetime data type resulted in an out-of-range value.
DECLARE @s nvarchar(255) SET @s = '12/1/2017' SELECT CONVERT(NVARCHAR(255),CONVERT(SMALLDATETIME,@s,105))works fine. But why are you converting back to nvarchar again? Convert both values to datetimes and then compare them. - ADysondate(time)as a(n)varchar. What is the result ofSELECT start+date FROM #temp2 WHERE TRY_CONVERT(smalldatetime,start_date,105) IS NULL AND start_Date IS NOT NULL;? - Larnu