Simple Insert problem, I think

  • I want to insert into a table from another table, and from a variable

    So Table_A has 3 columns (Fld_1, Fld_2, Fld_3), Table_B has 4 columns (Fld_1, Fld_2, Fld_3, FLD_4), . I want to insert the 3 columns from Table_A into table_B, as well as the variable @FLD4 into FLD_4. Can I do that in one statement ?

  • sure;

    declare @FLD4 int

    SET @FLD4=42

    INSERT INTO Table_B(Fld_1, Fld_2, Fld_3, FLD_4)

    SELECT Fld_1, Fld_2, Fld_3,@FLD4

    FROM Table_A

    homebrew01 (11/19/2008)


    I want to insert into a table from another table, and from a variable

    So Table_A has 3 columns (Fld_1, Fld_2, Fld_3), Table_B has 4 columns (Fld_1, Fld_2, Fld_3, FLD_4), . I want to insert the 3 columns from Table_A into table_B, as well as the variable @FLD4 into FLD_4. Can I do that in one statement ?

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • That was easy ! Thanks. I must have had a mental block thinking it wouldn't work that way because it looks like it's trying to select @FLD4 from Table_A

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

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