insert query (iteration)

  • Hello Everyone,

    i m using MySql,i have a table in this i have 3 clomun

    group_id    section_value     aro_id

    i want to insert maximum 700 records in this table but

    the problem is i have a constant value let say "18" in the column "group_id" , section_value is empty and the last column "aro_id varies from 15 to 700

    plz tell me how i inserted this type of record

    reply me asap

    its very urgent

  • I failed to understand your question, are u trying to understand how the data is inserted or do you want a solution for inserting the records as explained by you.

     

    Prasad Bhogadi
    www.inforaise.com

  • isa,

    You're pretty vague about where the data you are inserting is coming from.  This example assume you are inserting data from another table.

    Insert

       DestTable

          (

           group_id,

           section_value,

           aro_id

          )

    Select Top 700

       src.group_id,

       src.section_value,

       src.aro_id

    From

       SourceTable src

    Where

       src.group_id = 18

  • Thankyou so much for replying me , i want to insert new record in my table , not want to insert record which is coming from other table .

    i m using Mysql 4.1.

    thanx in advance.

  • It would appear that Isa want's to manufacture data (for test or otherwise) with a random number generator for the "Aro_ID" column.

    Isa, one question that remains is "Can there be dupes in the "Aro_ID" column?

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Hello Jeff, no there is no duplicates for "Aro_ID" column

  • Still not sure I understand the question, but maybe this is it?

    DECLARE @counter INT

    SET @counter = 14

    WHILE @counter < 700

    BEGIN

        SET @counter= @counter+1

        INSERT INTO your_table group_id, section_value, aro_id

        SELECT '18', NULL, @counter

    END

    I suppose this is just for one-time filling of a test table, not something you will call repeatedly during some procedure. If it isn't, you should consider other ways of doing this, because of performance.

    P.S.: This is SQL Server 2000 syntax (and SQL 2000 forums). I don't know MySQL, so I can't guarantee it will work there.

Viewing 7 posts - 1 through 6 (of 6 total)

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