1
Reply

How do i compare the values of Two Cursors and do update operation if the values matches.I am using Joins(Join query) in both the cursors.Please provide a appropriate solution(Working procedure) for this issue. Thanks in advance

vasanth svs

vasanth svs

14y
6.3k
0
Reply

    -- First Cursor

    -- DECLARE two variables
    DECLARE @fName1 varchar(50), @lName1 varchar(50)
    -- Declare cursor
    DECLARE cursor1 CURSOR
    FOR Select firstName, lastName FROM myTable1 INNER JOIN mytable2

    -- open the cursor
    OPEN cursor1

    -- Fetch a row from cursor into two variables
    FETCH NEXT FROM cursor1
    INTO @fName1, @lName1

    -- second cursor

    -- DECLARE two variables
    DECLARE @fName2 varchar(50), @lName2 varchar(50)
    -- Declare cursor
    DECLARE cursor2 CURSOR
    FOR Select firstName, lastName FROM myTable3 INNER JOIN mytable4

    -- open the cursor
    OPEN cursor2

    -- Fetch a row from cursor into two variables
    FETCH NEXT FROM cursor2
    INTO @fName2, @lName2

    -- Now compare the @fName1 wth fName2 and then lName1 with lName2 using IF

    IF @fName1 = @fName2 AND @lName = @lName

          -- DO UR TASK OF UPDATE

    Hope it is helpful to u though m late