Professional Web Applications Themes

insert into with select problem - Microsoft SQL / MS SQL Server

Try INSERT INTO dbo.SetParts ( SetPID , SetID ) SELECT SetPID , 552 /* SetID= 552 */ FROM SetParts WHERE SetID = 500 HTH, Srinivas Sampangi  below to use a  do is copy the  500 into a new  that I will  the syntax for  should create 10 new  value for each ...

  1. #1

    Default insert into with select problem


    Try

    INSERT INTO dbo.SetParts
    ( SetPID
    , SetID
    )
    SELECT SetPID
    , 552 /* SetID= 552 */
    FROM SetParts
    WHERE SetID = 500

    HTH,
    Srinivas Sampangi 
    below to use a 
    do is copy the 
    500 into a new 
    that I will 
    the syntax for 
    should create 10 new 
    value for each 
    sampangi Guest

  2. #2

    Default Re: insert into with select problem

    Thank you, I didn't know that I could just add the value into the select
    statement. It worked!

    Aaron

    sampangi wrote: 
    > below to use a 
    > do is copy the 
    > 500 into a new 
    > that I will 
    > the syntax for 
    > should create 10 new 
    > value for each [/ref]
    Aaron Guest

  3. #3

    Default Re: insert into with select problem

    I have the feeling that this is an adjacency list model for a tree in
    which set_id is the children node and set_pid is the parent node. If
    this is right, then we can do a much better job than this.

    But for now, this thing has no key, and you need to get rid of the
    IDENTITY columns and declare the actual key! This thing has no data
    integrity at all. Type in the same (set_id, set_pid) a thousand times
    and see what I mean. Which of these three options did you mean to say?
    Or should the non-key column be NULL-able?

    CREATE TABLE SetParts
    (set_id INTEGER NOT NULL,
    set_pid INTEGER NOT NULL,
    PRIMARY KEY (set_id, set_pid));

    CREATE TABLE SetParts
    (set_id INTEGER NOT NULL PRIMARY KEY,
    set_pid INTEGER NOT NULL);

    CREATE TABLE SetParts
    (set_pid INTEGER NOT NULL PRIMARY KEY,
    set_id INTEGER NOT NULL);
     [/ref]
    specific value for the set_id column? What I'm trying to do is copy the
    value of set_pid for all the records [sic] that have a set_id of 500
    into a new set of rows where the set_id for the new rows is something
    that I will specify. <<

    INSERT INTO SetParts(set_id, set_pid)
    SELECT 522, set_pid
    FROM SetParts
    WHERE set_id = 500;

    --CELKO--
    ===========================
    Please post DDL, so that people do not have to guess what the keys,
    constraints, Declarative Referential Integrity, datatypes, etc. in your
    schema are.

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Joe Guest

Similar Threads

  1. insert into...select
    By gehegeradeaus@gmail.com in forum MySQL
    Replies: 3
    Last Post: January 25th, 01:56 PM
  2. What's faster - loop for insert or insert...select.
    By mr. modus in forum Coldfusion Database Access
    Replies: 2
    Last Post: December 10th, 01:57 AM
  3. SELECT and INSERT
    By McKirahan in forum ASP Database
    Replies: 4
    Last Post: August 2nd, 05:45 PM
  4. Insert from Select
    By RPhillips@ce-a.com in forum Informix
    Replies: 6
    Last Post: July 30th, 10:16 PM

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