MySQL Forums
Forum List  »  General

Please identify whats problem in my query
Posted by: BIKASH KUMAR SUNDARAY
Date: June 19, 2014 03:09AM

DECLARE test_cur CURSOR FOR
SELECT a.Area_NId,c.Area_ID,c.Area_Name,a.Data_Value,a.Source_NId,a.Indicator_NId ,b.TimePeriod,a.Unit_NId,a.Source_NId
FROM undesso.ut_data a
LEFT JOIN undesso.ut_timeperiod b ON a.TimePeriod_NId=b.TimePeriod_NId
LEFT JOIN undesso.ut_area_en c ON a.Area_NId=c.Area_NId
LIMIT 1;


DECLARE CONTINUE HANDLER
FOR NOT FOUND SET finished = 1;

DECLARE Area_NId1 INT,Area_ID1 INT,Area_Name1 VARCHAR(100),Data_Value1 VARCHAR(100),Source_NId1 INT,Indicator_NId1 INT,TimePeriod1 VARCHAR(100),Unit_NId1 INT,Source_NId1 INT

OPEN test_cur
get_test_cur: LOOP
IF finished = 1 THEN LEAVE get_test_cur; END IF;
FETCH test_cur INTO Area_NId1 ,Area_ID1 ,Area_Name1 ,Data_Value1 ,Source_NId1 ,Indicator_NId1 ,TimePeriod1 ,Unit_NId1 ,Source_NId1

INSERT INTO unicef_new.data_masters(source_id,indicator_id,unit_id)VALUES(Source_NId1,Indicator_NId1,Unit_NId1);

DECLARE max_data_master_id INT,max_data_master_detail_id INT;
SET max_data_master_id:=0;
SET max_data_master_id=(SELECT IFNULL(MAX(data_master_id),0) FROM unicef_new.data_masters);

INSERT INTO unicef_new.data_master_details(data_master_id,indicator_id,YEAR)
VALUES(max_data_master_id,Indicator_NId1,TimePeriod1);

SET max_data_master_detail_id:=0;
SET max_data_master_detail_id=(SELECT IFNULL(MAX(data_master_detail_id),0) FROM unicef_new.data_master_details);

IF Area_NId=1 THEN

INSERT INTO unicef_new.state_populations(data_master_id,data_master_detail_id,state_code,state_population)
VALUES(max_data_master_id ,max_data_master_detail_id,Area_ID1,Data_Value1);

ELSEIF Area_NId BETWEEN 2 AND 31 THEN
INSERT INTO unicef_new.dist_populations(data_master_id,data_master_detail_id,district_code,dist_population)
VALUES(max_data_master_id ,max_data_master_detail_id,Area_ID1,Data_Value1);

ELSE
INSERT INTO unicef_new.block_populations(data_master_id,data_master_detail_id,block_code,block_population)
VALUES(max_data_master_id ,max_data_master_detail_id,Area_ID1,Data_Value1);

END IF;

END LOOP get_test_cur;

CLOSE test_cur;

Options: ReplyQuote


Subject
Written By
Posted
Please identify whats problem in my query
June 19, 2014 03:09AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.