select * into works but insert into select gives conversion error

  • I am inserting some data from a self join CTE into a table. When i do select * into to load data into that table it works fine. But when i use insert into, it returns 'Conversion failed when converting date and/or time from character string' error. My source and destination columns related to date are both declared as datetime.

  • s.kandepi3 (12/21/2015)


    I am inserting some data from a self join CTE into a table. When i do select * into to load data into that table it works fine. But when i use insert into, it returns 'Conversion failed when converting date and/or time from character string' error. My source and destination columns related to date are both declared as datetime.

    Can you provide any actual information here? Things like table definitions, the code you are using, sample data etc. Without this information nobody can do anything but guess. Take a look at this article for the kinds of information you need to be posting. http://spaghettidba.com/2015/04/24/how-to-post-a-t-sql-question-on-a-public-forum/[/url]

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • s.kandepi3 (12/21/2015)


    I am inserting some data from a self join CTE into a table. When i do select * into to load data into that table it works fine. But when i use insert into, it returns 'Conversion failed when converting date and/or time from character string' error. My source and destination columns related to date are both declared as datetime.

    If both source and target are datetime, I cannot see how you would ever get this error. Unless you are doing something to affect datatypes in your CTE.

    So please post the CTE, showing how the offending column is being used.

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

  • From the error, you're doing something with a string column, but without DDL for the tables and the CTE, anything I say would be a guess.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply