SQL Server datetime type conversion out of range error

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.