If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > "SIN"tatic Prodecure

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-08-09, 07:09
skarri skarri is offline
Registered User
 
Join Date: Sep 2008
Posts: 16
"SIN"tatic Prodecure

Here is procedure which does its work perfectly a number is given to the where clause
but here i wanted to generate that value from a sql select query(10th line) and give it to the declaration cursor
how do i do it?
Quote:
DELIMITER $$
DROP PROCEDURE IF EXISTS `DEV`.`spClaimUserArchive`$$
CREATE PROCEDURE `spClaimUserArchive`()
BEGIN
DECLARE vClaim varchar(15);
DECLARE vRefUserId varchar(15);
DECLARE vClaimEntered char(1);
DECLARE vbatch varchar(15) ;
DECLARE no_more_rows BOOLEAN;


select max(Batch) into vbatch from tblClaimUser ;
DECLARE curClaimUserArchive CURSOR FOR select Claim,RefUserId,ClaimEntered from tblClaimUserArchive where Batch=vbatch ;
DECLARE CONTINUE HANDLER FOR NOT FOUND

SET no_more_rows = TRUE;


OPEN curClaimUserArchive;

curClaimUserArchive_loop: LOOP

FETCH curClaimUserArchive into
vClaim,vRefUserId, vClaimEntered;
IF no_more_rows THEN
insert into tblClaimUserArchive select * from tblClaimUser ;
truncate table tblClaimUser;

CLOSE curClaimUserArchive;

LEAVE curClaimUserArchive_loop;

END IF ;
delete from tblClaimUserArchive where Batch=vbatch ;
END LOOP curClaimUserArchive_loop;
CLOSE curClaimUserArchive;
END
$$
DELIMITER ;
__________________
"TALK SENSE TO FOOL. HE CALLS U FOOLISH"

Last edited by skarri; 06-08-09 at 07:48.
Reply With Quote
  #2 (permalink)  
Old 06-08-09, 07:57
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,519
Why don't you tell us what it is you're trying to do rather than let us try and work it out by going through all your code. My initial guess is that if you're using cursors then you're doing it the wrong way anyway.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On