help begginer to loop with T-SQL

  • I'm new in T-SQL,

    can someone help me with big problem for me, but redicilus problem for a T-SQL programmer?

    I have 3 tables:

    Table1, Table2, Table3

    Table1 is having 100 records (fields are: ID_T1 (auto), Col1, Col2,...)

    Table2 is having 20 records (fields are: ID_T2 (auto), Col1, Col2,...)

    Table3 is empty (Fields are: ID_T3 (auto), ID_T1, Col1, Col2,...)

    What I want to do is with T-SQL loop to insert in Table3 for each row in Table1 all records from Table2.

    I want to build a test data for testing relational tables.

    Thnx, Davor

  • Davor Geci (12/17/2008)


    I'm new in T-SQL,

    can someone help me with big problem for me, but redicilus problem for a T-SQL programmer?

    I have 3 tables:

    Table1, Table2, Table3

    Table1 is having 100 records (fields are: ID_T1 (auto), Col1, Col2,...)

    Table2 is having 20 records (fields are: ID_T2 (auto), Col1, Col2,...)

    Table3 is empty (Fields are: ID_T3 (auto), ID_T1, Col1, Col2,...)

    What I want to do is with T-SQL loop to insert in Table3 for each row in Table1 all records from Table2.

    I want to build a test data for testing relational tables.

    Thnx, Davor

    Have a look in BOL for INSERT...FROM.

    โ€œWrite the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.โ€ - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden

  • Thnx Ten, for tip.

    I have resolved the generation of the test data with INSERT INTO & cross join.

    Davor

    ๐Ÿ™‚

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

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