Help in T-SQL Query

  • Dear Friendz,

    Need help in building a query.  I've 2 tables with the following strucuture..

    mstBranch ( BranchID PK IDENT INT , BankCode V(50) N.N. , BankName V(100) N.N. , BranchCode V(50) N.N. , BranchName V(100) N.N. )

    IndSales ( IndSalesID PK IDENT INT , BankCode V(50) N.N. , BranchCode V(50) N.N. , ProductCode V(50) N.N. , PolicyNo V(50) , Premium NUMERIC(18,2) N.N. )

    Each table will have 14000+ records. Now i need to all the records from IndSales which are not in mstBranch.

    There are indirectly linked with BankCode & BranchCode fields.  I know i can do it with using correlated queries, but i want to know is there is any other way i can do this?

    Thanks in advance.

    Regards,

    Ramesh

    --Ramesh


  •  SELECT i.*

       FROM IndSales i

       LEFT OUTER JOIN mstBranch b

                    ON i.BankCode   = b.BankCode

                   AND i.BranchCode = b.BranchCode

      WHERE b.BankCode IS NULL

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

  • Jeff,

    Thanks for the query...

     

    --Ramesh

     

    --Ramesh


  • You bet, Ramesh... thank you for the feedback.

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