A very basic INSERT statement:
INSERT INTO Table1select col1,convert (datetime,col2), convert (datetime,col3), col4,col5 from table2
The col2,col3 in the Table1 table are datetime types, others are varchar types, and table2 are all varchar types.
The Table2 table is all varchar types, and Col 1 4 5 may be null values.
The following error occurred in the execution times:
MSG 242, Level 16, State 3, line 1th the conversion from the varchar data type to the datetime data type produces an out-of-range value. Statement has been terminated.
Because the datetime type only involves Col 2 32 columns, it checks for a long time whether the data for these two columns is canonical, but the final discovery is not an issue of nonstandard data.
The INSERT statement is written as:
Insert INTO table1 (COL1,COL2,COL3,COL4,COL5) Select Col1,convert (datetime,col2), convert (datetime,col3), COL4,COL5 From table2
Will not be an error, it should be failed to specify the column name, resulting in matching the value of the other columns to match the datetime column caused, so SQL Server insert INTO ... select ... It is necessary to specify the name of the column, just remember it.
SQL Server datetime type conversion out of range error