How to Fix the out-of-range value during inserting the values

Hi team,

while inserting data from one table to another table. i am getting the below error.

SQL:
INSERT INTO dbo.Salesoffice_PLATFORM (DATENEW, USERNEW, ID, COUNTRYID, PLATFORMDESCRIPTION, PLATFORMGUID, VALIDFROM, VALIDTO) VALUES ('2020-09-01 13:12:41.06', 1589, '6EC029307AB11C4EB6D2FDE902F3EF34','20EA4D17A556514CA78287EBE9652ABC', 'Test' , '842BF8329EBE43ECAD890F50713AA988', '2014-07-22 22:00:00', '9999-12-31 23:00:00')

Error

[ODBC Driver 17 for SQL Server][SQL Server]The conversion of a datetime2 data type to a smalldatetime data type resulted in an out-of-range value.

Source table - Platform

  1. VALIDFROM datetime
  2. VALIDTO datetime

Destination table - salesOfficePlatform

VALIDFROM smalldatetime
VALIDTO smalldatetime

Is it possible to fix the issue without changing the datatype in the destination table. ?

Yes

Using CAST or Convert

example ..

ID is int and ID_Name is varchar

cast( id as varchar) = ID_Name

'9999-12-31 23:00:00')
is this a real date in real table?

smalldatetime supports
January 1, 1900, through June 6, 2079

1 Like