Mysql Stored procedure with cursor

Viewed 84191

Mysql cursor issue?

I have written a stored procedure which will travel's record from one table and insert those into 2-3 different tables using insert statements.

Problem is that i am checking if record is not exists in table1 then I am inserting record from temptable to table1 ,table2 sequentially ,but the condition is having some problem i don't know it its always going into else part.

Code sample is as follows:

CREATE PROCEDURE `insertData`(In clientNo INT,In usedID INT)
BEGIN

declare mame varchar(100);
declare address varchar(100);
declare city varchar(50);
declare IdentityNO1 varchar(20)


declare cur1 cursor for select * from temptable;
declare continue handler for not found set done=1;

SET @clientNo = clientNO;
SET @userID = userID;


    set done = 0;
    open cur1;
    igmLoop: loop
        fetch cur1 into Name,Address,City,IdentityNO1,clientNo;
        if done = 1 then leave igmLoop; end if;

        //If no record exists in some records table1,table2.
        IF ( (SELECT COUNT(*) FROM table1 
               WHERE IndentityNo=IdentityNo1 
                 AND clientNo=@clientNo) < = 0)
              INSERT INTO table1 (Name,IdentityNO) VALUES (name,IdentityNO1);
              INSERT INTO table2 (Address,City) VALUES(address,city);
        ELSE
              INSERT INTO tblexceptional(Name,Address,City,IdentityNo)
              VALUES(name,address,city,IdentityNo1);
    end loop igmLoop;
    close cur1;
END
1 Answers
Related