Professional Web Applications Themes

For Each .... - Microsoft SQL / MS SQL Server

Could someone give me a hand here ... I am looking to perform a select stmnt in a SQL SP... something along the lines of: select id_name, first, last, pid from tbl_build_test where id = PID (where PID would be an incoming var from an ASP) Then that returns .. .say 5 rows ... I would like to re-insert those results into the same table, but with a new PID ?...

  1. #1

    Default For Each ....

    Could someone give me a hand here ... I am looking to perform a select stmnt
    in a SQL SP... something along the lines of:

    select id_name, first, last, pid
    from tbl_build_test
    where id = PID

    (where PID would be an incoming var from an ASP)

    Then that returns .. .say 5 rows ...

    I would like to re-insert those results into the same table, but with a new
    PID ?


    David Guest

  2. #2

    Default Re: For Each ....

    Sweet. Thanks Aaron.

    "Aaron Bertrand - MVP" <com> wrote in message
    news:phx.gbl... 
    > stmnt 
    > new 
    >
    >[/ref]


    David Guest

  3. #3

    Default Re: For Each ....

    Follow up question :)

    Say I performed an insert previous to this:

    INSERT INTO tbl_test_2 (gid, lcid, tmp2)
    (var1, var2, var3)

    the PK for tbl_test_2 is PID -- the SAME PID I would like to use in the
    following insert ...

    INSERT tbl_build_test ( name, first, last, pid )
    SELECT name, first, last, newpid
    FROM tbl_build_test WHERE pid = pid ;

    would it look something like ,,

    DECLARE pid int
    set pid = identity ???


    David Guest

  4. #4

    Default Re: For Each ....

    > would it look something like ,, 

    That depends. In SQL Server 7.0, yes. In SQL Server 2000, SCOPE_IDENTITY()
    is safer than IDENTITY.


    Aaron Guest

  5. #5

    Default Re: For Each ....

    yeah. I'm using sql 2k ...
    scope_identity eh ? thanks, I'll hit up BOL.


    "Aaron Bertrand - MVP" <com> wrote in message
    news:%phx.gbl... 
    >
    > That depends. In SQL Server 7.0, yes. In SQL Server 2000,[/ref]
    SCOPE_IDENTITY() 


    David Guest

Bookmarks

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139