Looping statement other than using CURSOR RRS feed

  • Question




    Can you help me?

    I have 2 queries.

    I created a temp table to insert the result of my 1st query.

    I need to use the values in my temp table to pass it on my 2nd query.

    The problem is, my team lead doesn't allow me to use cursor.

    How am I suppose to use the values I have in my tempt table to use for my second query?


    This is my first table that was already in my temptable

    Select lastname, age, id from table1


    2nd query

    --need to have a looping statement here using each records I have in my temptable

    select name, dept from temp2

    where lastname = lastname -- name from my 1st query

    and id = id -- id from my 1st query


    --end of loop--







    Thursday, January 29, 2009 1:04 PM

All replies

  • Can't you join both the tables in one SQL or use Co-related sub query to get the desired result without using CURSOR?  I dont see a need for cursor for this SQL...

    A Sample from wikipedia...
    SELECT Employee.lastName, Employee.DepartmentID, Department.DepartmentName
    FROM Employee INNER JOIN Department
    ON Employee.DepartmentID = Department.DepartmentID;

    {Gaja; }
    Pl mark if answer solves your problem | Visit for .net ref Arch
    Monday, February 2, 2009 9:00 PM