sql help

  • can anyone please help me in writing queries for the below -

    1. Select from Table1 where WDSBAR = 'xyz'

    2. Store into another table (Table2) the following fields:

       a.WDBCI, WDDGL, WDPRSQ, WDSBSQ, WDCCOD, WDSLNK

    3. Using the fields that were stored on the table bulit in step 2 (Table2), join to Table1 where each of the 6 fields above is equal to the value in the new table(Table2) and WDDOCZ <>'0' in Table1

    4. Copy the fields listed below from Table1 into Table2:

       a. WDIDGJ, WDDCTL, WDDOCZ,WDKCOL,WDJEL,WDSFX,WDICU,WDAPPO

    5. Using the fields listed in step 2above, and WDSBAR = 'xyz', join from the Table2 table to the Table1 table and update Table1 with the values in the 8 fields listed in step4 above.

    Thanks in advance!!!

  • Hello

    1) SELECT * FROM Table1 WHERE WDSBAR='xyz'

    2) CREATE TABLE Table2 (

    WDBCI <your type>

    , WDDGL <your type>

    , WDPRSQ <your type>

    , WDSBSQ <your type>

    , WDCCOD <your type>

    , WDSLNK <your type>

    )

    3) SELECT T1.*, T2.*

    FROM Table1 AS T1 ,Table2 AS T2

    WHERE T1.WDBCI=T2.WDBCI

    AND T1.WDDGL=T2.WDDGL

    AND T1.WDPRSQ=T2.WDPRSQ,

    AND T1.WDSBSQ=T2.WDSBSQ

    AND T1.WDCCOD=T2.WDCCOD

    AND T1.WDSLNK=T2.WDSLNK

    AND T1.WDDOCZ <>'0'

    4)

    INSERT INTO Table2 (WDIDGJ, WDDCTL, WDDOCZ,WDKCOL,WDJEL,WDSFX,WDICU,WDAPPO)

    SELECT WDIDGJ, WDDCTL, WDDOCZ,WDKCOL,WDJEL,WDSFX,WDICU,WDAPPO

    FROM Table1

    5) That is what I cannot understand ....

     

    Kindest Regards,

    Damian Widera
    SQL Server MVP,
    MCT, MCSE Data Platform, MCSD.NET

  • Damian, thanks a lot for your quick response -

    Regards!!!

  • Did you get an "A" on the homework?

    --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)

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

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