SQL - INSERT INTO... SELECT statement

  • [p]I am trying to insert multiple rows from table 2 to table 1.[/p]

    [p]The value RID in table 1 is the same as the value ID in table 2.[/p]

    [p]So for the criteria satisfying the condition in table 2 - where (Posting=1111) AND (Status = 'New'), I want to insert rows into the table 1 and the values for Action, ActionDate, ActionBy, EffectiveDate, must be the same ('New to No', 11/14/2008, 'XYZ', 11/14/2008) in all the inserted rows.[/p]

    Insert into table1 (RID, Action, ActionDate, ActionBy, EffectiveDate)

    Select ID from table2 where (Posting=1111) AND (Status = 'New'), 'New to No', 11/14/2008, 'XYZ', 11/14/2008

    [p]Please help[/p] 🙁

    Thanks

    Newbie to SQL Server

    Customer First
    TeamWork
    Open Communication
  • Try the script below

    Insert into table1 (RID, Action, ActionDate, ActionBy, EffectiveDate)

    Select ID,'New to No', '11/14/2008', 'XYZ', '11/14/2008' from table2 where (Posting=1111) AND (Status = 'New')

    "-=Still Learning=-"

    Lester Policarpio

  • Could you post the create statements for both tables, sample data for both tables, the expected results after the query (the insert inthis case) is run, and the code you have already written to attempt the action you are attempting.

    Please read the article in the link shown below in my signature block for more information on how to accomplish the above request.

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

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