Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2005
    Posts
    266

    Unanswered: INSERT from different tables and values

    Hello

    for MS SQL 2000

    I am having MyTable with 7 columns : A,B,C,D,E,F,G

    i want to

    INSERT INTO myTable
    SELECT A,B,C,D FROM FirstTable WHERE FirstTable.ID > 100


    and the columns E,F,G :
    E = 1
    F = SELECT Max(ID) AS F FROM SecondTable
    G = 0


    how can i do it ?
    i would like to create a stored procedure

    thank you

  2. #2
    Join Date
    May 2004
    Location
    Seattle
    Posts
    1,313
    this should do it.

    declare @f int
    select @f = Max(ID) FROM SecondTable

    INSERT INTO myTable
    SELECT A,B,C,D,1,@f,0 FROM FirstTable WHERE FirstTable.ID > 100

  3. #3
    Join Date
    Dec 2005
    Posts
    266
    it works fine !

    thanks a ton
    Last edited by anselme; 10-19-06 at 02:54.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •