Column data type - Msg 207 Invalid column name

  • gjoelson 29755 - Thursday, November 1, 2018 2:52 PM

    Joe Torre - Wednesday, October 31, 2018 5:18 PM

    Here is you query written as "insert into select"
    USE [SSSUTIL]
    GO
    INSERT INTO [dbo].[CustomerOrders]
    ([co_num]
    ,[cust_po]
    ,[co_line]
    )
    SELECT 38322, 'B123', 2;
    GO

    It doesn't matter if it's written as insert/select or insert/values, you still need to put single quotes around your strings.

    Joe, not sure how I would put quotes around all the values on an insert/select since I'm select directly from a table  ?

    Don't worry about adding quotes when selecting data from a table.

  • Lynn Pettis - Thursday, November 1, 2018 3:01 PM

    gjoelson 29755 - Thursday, November 1, 2018 2:52 PM

    Joe Torre - Wednesday, October 31, 2018 5:18 PM

    Here is you query written as "insert into select"
    USE [SSSUTIL]
    GO
    INSERT INTO [dbo].[CustomerOrders]
    ([co_num]
    ,[cust_po]
    ,[co_line]
    )
    SELECT 38322, 'B123', 2;
    GO

    It doesn't matter if it's written as insert/select or insert/values, you still need to put single quotes around your strings.

    Joe, not sure how I would put quotes around all the values on an insert/select since I'm select directly from a table  ?

    Don't worry about adding quotes when selecting data from a table.

    So if it works when I do an insert with values using quotes, and it doesn't work using a select , does this have to do with the data type ?

  • No.

    The error says exactly what is wrong. Somewhere, either in the insert itself or maybe in a trigger, you're referencing a column that does not exist.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • gjoelson,
    It would behoove you to read the Microsoft SQL Server documentation on insert and the WC3 INSERT INTO  and INSERT INTO SELECT documentation.

Viewing 4 posts - 31 through 33 (of 33 total)

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