Here is my procedure :
delimiter //
drop procedure if exists migContactToActor;
create procedure migContactToActor()
begin
declare vctaid int;
declare firstname char(255);
declare lastname char(255);
declare phone char(255);
declare cellphone char(255);
declare fax char(255);
declare mail char(255);
declare location char(255);
declare extcode char(255);
declare vcpyid int;
declare vquaid int;
declare userModif char(255);
declare entityIdResp int;
declare niveauCreat char(255) default "contactMigration2.21";
declare userCreat char(255) default "contactMigration2.21";
declare backIdResp int;
declare userIdResp int;
declare zipcode char(255);
declare country char(255);
declare dateModif char(255);
declare dateCreated char(255);
declare dateRelation char(255);
declare groupLabel char(255);
declare adminLogId int;
declare finContact boolean default 0;
declare ctt int default 1; /* decompte contacts */
declare entityName char(255) default ''; /* entite courante du user a linker */
declare entityId int default 0; /* et son Id */
declare vctaidPrev int default 0;
declare curs1 cursor for select
ctaid, ctafirstname,ctalastname,ctaphone,ctacellphone,ctaemail,
substr(concat_ws(' ',ctaaddress,ctaaddress2,ctacity,ctazipcode),1,255),ctacode, cpyid,quaid,C.enoid_resp,
ctafax,C.actid_bck,ctadate_created,ctacountry,ctadate_modified,C.actid_resp,ctauser_modified, G.hemlabel, R.sync_update
from contact C
left join hd_contact_group_relationship R on R.hbhid = C.ctaid
left join hd_contact_group G on G.hemid = R.hemid
where !ifnull(C.ctaflagdeleted,0) and !ifnull(G.hemflag_deleted,0);
declare continue handler for not found set finContact = 1;
declare continue handler for sqlexception
begin
rollback;
end;
select '======== debut ...';
drop table if exists ent221;
create temporary table ent221 as select enoid, enoname from entityowner where enoname like 'CLI.CG_%.CLI';
alter table ent221 add index(enoname); /* not unique in dev, fetch the first in prod if any */
set autocommit = 0; /* TTT */
start transaction; /* TTT */
open curs1;
contactloop:loop
fetch curs1 into vctaid, firstname,lastname,phone,cellphone,mail,location,extcode,vcpyid,vquaid,entityIdResp,
fax,backIdResp,dateCreated,country,dateModif,userIdResp,userModif,groupLabel,dateRelation;
if finContact then
close curs1;
leave contactloop;
end if;
if vctaid = vctaidPrev then
set vctaidPrev = vctaid;
if (mod(ctt,100) = 0) then
set #msg = concat(ctt, ' contacts migrated');
select #msg;
end if;
update OPMSequence set counter = (#wbuf1 := counter) + 1 where name = 'ACTOR';
insert into actor (actid,cpyid,actlastname,actfirstname,actemail,actphone,actmobilephone,
actlocalisation, actid_responsible_owner,actid_backup_owner,enoid_responsible_owner,
actuser_created,actniveau_created, actdate_created,actuser_modified,
actdate_modified,actcountry,actfax,actqualifid,actexternal_code)
values
(#wbuf1,vcpyid,lastname,firstname,mail,phone,cellphone,location,userIdResp,backIdResp,entityIdResp,
userCreat,niveauCreat,dateCreated,userModif,dateModif,country,fax,vquaid,extcode);
update adminLog set adltype = 'User', adlobject_id = #wbuf1,
adlobject_description = concat(adlobject_description,'//oldContact=',vctaid)
where adlobject_id = vctaid and adltype = 'Contact';
end if;
if groupLabel is not null then
set #entName = concat('CLI.CG_',groupLabel,'.CLI);
select enoid from ent221 where enoname = #entName limit 1 into #wbuf2;
if #wbuf2 is not null then
insert into actorentityrelationship (enoid,actid,aerdate_created,aerniveau_created) values
(#buf2,#wbuf1,dateRelation,niveauCreat);
enf if;
end if;
set ctt = ctt + 1;
end loop contactloop;
rollback; /* TTT */
end //
delimiter ;
call migContactToActor;
drop procedure migContactToActor;
Why this ???
Query OK, 0 rows affected, 1 warning (0.00 sec)
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''.CLI);
select enoid from ent221 where enoname = #entName limit 1 into #wbuf2' at line 83
I think you missed the quotes
set #entName = concat('CLI.CG_',groupLabel,'.CLI);
with quotes
set #entName = concat('CLI.CG_',groupLabel,'.CLI');
Related
DROP PROCEDURE CREATE_DUPLICATE_PRODUCT;
DELIMITER $$
CREATE PROCEDURE `CREATE_DUPLICATE_PRODUCT`(IN `old_course_id` INT(25), IN `new_course_id`
INT(25))
BEGIN
DECLARE db_cursor CURSOR FOR SELECT lic.org_id, lic.course_id, lic.license_duration_typeid, lic.insert_date, lic.insert_by, lic.quantity FROM cdp_organization_licenses as lic JOIN cdp_organization_license_settings as sett ON sett.org_license_id = lic.id JOIN cdp_organization_purchases as pur ON pur.org_id = lic.org_id AND pur.course_id = lic.course_id JOIN cdp_organizations as org ON org.org_id = lic.org_id WHERE lic.status_id = 1 AND org.status_id = 1;
DECLARE #org_id INT;
DECLARE #course_id INT;
DECLARE #license_typeid INT;
DECLARE #insert_date INT;
DECLARE #insert_by INT;
DECLARE #quantity INT;
OPEN db_cursor;
FETCH NEXT FROM db_cursor INTO #org_id, #course_id,
#license_duration_typeid, #insert_date, #insert_by, #quantity;
WHILE ##FETCH_STATUS = 0
BEGIN
--Do stuff with scalar values
FETCH NEXT FROM db_cursor INTO #org_id, #course_id,
#license_duration_typeid, #insert_date, #insert_by, #quantity;
INSERT INTO cdp_organization_licenses_test
SET
org_id = #org_id,
course_id = #course_id,
license_duration_typeid = #license_duration_typeid,
insert_date = #insert_date,
insert_by = #insert_by,
quantity = #quantity;
END;
CLOSE db_cursor;
DEALLOCATE db_cursor;
END$$
DELIMITER ;
I am getting this error:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '#org_id INT;
DECLARE #course_id INT;
DECLARE #license_typeid INT; ' at line 5
What can I do to resolve this?
You are mixing sql serv and mysql , that can not work
DROP PROCEDURE CREATE_DUPLICATE_PRODUCT;
DELIMITER $$
CREATE PROCEDURE `CREATE_DUPLICATE_PRODUCT`(IN `old_course_id` INT(25), IN `new_course_id`
INT(25))
BEGIN
DECLARE _org_id INT;
DECLARE _course_id INT;
DECLARE _license_typeid INT;
DECLARE _insert_date INT;
DECLARE _insert_by INT;
DECLARE _quantity INT;
DECLARE finished INTEGER DEFAULT 0;
DECLARE db_cursor CURSOR FOR
SELECT lic.org_id, lic.course_id, lic.license_duration_typeid, lic.insert_date, lic.insert_by, lic.quantity
FROM cdp_organization_licenses as lic
JOIN cdp_organization_license_settings as sett ON sett.org_license_id = lic.id
JOIN cdp_organization_purchases as pur ON pur.org_id = lic.org_id AND pur.course_id = lic.course_id
JOIN cdp_organizations as org ON org.org_id = lic.org_id
WHERE lic.status_id = 1 AND org.status_id = 1;
DECLARE CONTINUE HANDLER
FOR NOT FOUND SET finished = 1;
OPEN db_cursor;
getinfo: LOOP
BEGIN
FETCH NEXT FROM db_cursor INTO _org_id, _course_id,
_license_duration_typeid, _insert_date, _insert_by, _quantity;
IF finished = 1 THEN
LEAVE getEmail;
END IF;
INSERT INTO cdp_organization_licenses_test
SET
org_id = _org_id,
course_id = _course_id,
license_duration_typeid = _license_duration_typeid,
insert_date = _insert_date,
insert_by = _insert_by,
quantity = _quantity;
END;
END LOOP getinfo;
CLOSE db_cursor;
END$$
DELIMITER ;
But t´you can simply do a
INSERT INTO cdp_organization_licenses_test
SELECT lic.org_id, lic.course_id, lic.license_duration_typeid, lic.insert_date, lic.insert_by, lic.quantity
FROM cdp_organization_licenses as lic
JOIN cdp_organization_license_settings as sett ON sett.org_license_id = lic.id
JOIN cdp_organization_purchases as pur ON pur.org_id = lic.org_id AND pur.course_id = lic.course_id
JOIN cdp_organizations as org ON org.org_id = lic.org_id
WHERE lic.status_id = 1 AND org.status_id = 1;
That makes all with out the loop
Don't DECLARE variables with # at the beginning of their names. Those are session variables, don't need to be declared, and have session-wide scope,
This is my code:
BEGIN
DECLARE _cnt INT;
DECLARE i INT DEFAULT 0 ;
DECLARE j INT DEFAULT 0 ;
DECLARE _FIPSAPNCombo VARCHAR(30) DEFAULT '00000';
DECLARE _prv_FIPSAPNCombo VARCHAR(30) DEFAULT '00000';
DECLARE _Rollyear INT DEFAULT 2000;
DECLARE _first_Rollyear INT DEFAULT 2000;
DECLARE eof boolean default FALSE;
DECLARE _AvTotal INT;
DECLARE _prv_AvTotal INT default 0;
DECLARE _YOY_PCT INT;
DECLARE _YOY_USD INT;
DECLARE _in_pct INT;
DECLARE _in_usd INT;
DECLARE _last INT;
DECLARE _id INT;
DECLARE _idx INT;
DECLARE _prv_id INT;
DECLARE get_FIPSAPNCombo CURSOR
FOR
SELECT 0, '0', 2000, 1
UNION
SELECT id, FIPSAPNCombo, rollyear, AvTotal
FROM AvHistory_06037 AS h
WHERE substr(h.FIPSAPNCombo,1,8) = _in_FIPSAPNCombo_8
AND h.AvTotal > 0
ORDER BY 2, 3
;
DECLARE CONTINUE HANDLER
FOR NOT FOUND
SET eof = TRUE;
SELECT YOY_PCT, YOY_USD INTO _in_pct, _in_usd FROM AlertSearches WHERE id = _in_AlertSearchesID;
START TRANSACTION;
OPEN get_FIPSAPNCombo;
doit: LOOP
fetch get_FIPSAPNCombo INTO _id, _FIPSAPNCombo, _Rollyear, _AvTotal;
SET _YOY_USD = _AvTotal - _prv_AvTotal;
SET _YOY_PCT = ROUND((((_AvTotal - _prv_AvTotal) / _prv_AvTotal) * 100),0);
IF eof = TRUE THEN
LEAVE doit;
END IF;
IF _FIPSAPNCombo != _prv_FIPSAPNCombo THEN SET _first_Rollyear = _Rollyear; ELSE SET _first_Rollyear = '2000'; END IF;
IF _YOY_PCT >= _in_pct AND _YOY_USD >= _in_usd and _Rollyear != _first_Rollyear THEN
BEGIN
DELETE FROM AvHistoryAlerts WHERE FIPSAPNCombo = _FIPSAPNCombo AND AlertSearchesID = _in_AlertSearchesID;
INSERT INTO AvHistoryAlerts VALUES (_id, _FIPSAPNCombo, '06037', _Rollyear, _AvTotal, _YOY_PCT, _YOY_USD, _prv_id, _prv_AvTotal, _in_AlertSearchesID);
UPDATE AvHistory SET CausalTransfer = NULL WHERE FIPSAPNCombo = _FIPSAPNCombo;
UPDATE AvHistory SET CausalTransfer = 'Green' WHERE id = _id;
SET i = i + 1;
IF mod(i,1000) = 0 THEN insert into error_log VALUES (concat(_in_FIPSAPNCombo_8, ' > calc_YOY_increase i = ', i, ' ',now())); COMMIT; START TRANSACTION; END IF;
END;
END IF;
SET _prv_FIPSAPNCombo = _FIPSAPNCombo;
SET _prv_AvTotal = _AvTotal;
SET _prv_id = _id;
SET eof = FALSE;
END LOOP;
COMMIT;
CLOSE get_FIPSAPNCombo;
END
I thought that the procedure would commit every 1000 records processed and that this would be reflected in the error_log table in real time.
But, the data is only available after the procedure finishes completely and then all the records show up all at once in the error_log table.
That, by itself, is not the issue: what I am concerned about is the the procedure seems to dwell on "waiting for handler commit" for a long time at the end of the procedure.
So, I'm not sure what's going on: is it storing everything in memory or in a temp table or file and then needs a lot if time for cleanup?
I thought that a commit would clear all that... but it does not seem to commit until the end of the whole procedure
Any ideas?
Below procedure code running with out error . Line select FOUND_ROWS() returning n no. rows but cursor curs did not loop all rows
CREATE DEFINER=`root`#`%` PROCEDURE `middleLocationAutoUpdatePorc`()
BEGIN
declare vname varchar(45);
declare vmobile varchar(20);
declare vsapid varchar(6);
declare vuser varchar(45);
declare vday date;
declare vmintime time;
declare vmaxtime time;
declare vminLocation mediumtext;
declare vmaxLocation mediumtext;
declare vmiddlelocation mediumtext;
declare vdistance int(11);
declare vdrdid int(11);
declare vn_no_details int(11);
declare uatt varchar(45) default 'X';
declare adatta varchar(45) default 'X';
declare b_not_found BOOL DEFAULT FALSE;
declare curs CURSOR FOR
SELECT user ,day, mintime,maxtime_mobile,minLocation,maxLocation,distance,n_no_details,drdid FROM mydb.statusreport where day >= '2017-06-26';
DECLARE CONTINUE HANDLER FOR NOT FOUND SET b_not_found = true;
OPEN curs;
loop1: LOOP
FETCH curs INTO vuser,vday,vmintime,vmaxtime,vminLocation,vmaxLocation,vdistance,vn_no_details,vdrdid;
IF b_not_found THEN
LEAVE loop1;
END IF;
-- select FOUND_ROWS();
case substring_index(vuser,"-",-1)
when 'RSM' then
select username,Name,mobile into vsapid,vname,vmobile from mydb.supervisor where idSu=CONVERT(substring_index(vuser,"-",1),UNSIGNED INTEGER);
when 'ASM' then
select userName,name,mobile into vsapid,vname,vmobile from mydb.executive where exeid=CONVERT(substring_index(vuser,"-",1),UNSIGNED INTEGER);
when 'F' then
select sapId,name,phone into vsapid,vname,vmobile from mydb.user where idUser=CONVERT(substring_index(vuser,"-",1),UNSIGNED INTEGER);
end case;
select userGiven , adminGiven into uatt ,adatta from userdaystatus st where st.date =vday and st.idUser=CONVERT(substring_index(vuser,"-",1),UNSIGNED INTEGER) and st.userType=substring_index(vuser,"-",-1);
set vmiddlelocation=( select location from mydb.dailyReportDetails as dtb where dtb.idDailyReport=vdrdid and dtb.counter>=(abs(vn_no_details/2) ) order by dtb.idDailyReportDetails asc limit 1);
call mydb.addOMiddleLocation(day(vday), month(vday),
year(vday),vuser, vname,
vsapid, vmobile, vmintime,
vmaxtime, SUBTIME(vmaxtime,vmintime),
vminLocation,
vmiddlelocation,
vmaxLocation,Round(vdistance/1000,2),
uatt, adatta);
END LOOP;
CLOSE curs;
END
The Procedure call mydb.addOMiddleLocation() just inserting Row on another table.There does not have any data type validation .
So what can be the problem ?
It happen for log wait time for a particular Query line
set vmiddlelocation=( select location from mydb.dailyReportDetails as dtb where dtb.idDailyReport=vdrdid and dtb.counter>=(abs(vn_no_details/2) ) order by dtb.idDailyReportDetails asc limit 1);
I have a stored procedure like this :
DROP PROCEDURE IF EXISTS storedprocedure;
CREATE DEFINER = 'userid'#'%' PROCEDURE storedprocedure
(IN id int)
BEGIN
DECLARE cor int;
DECLARE sup int;
DECLARE faktur varchar(20);
DECLARE ptgs int;
DECLARE suppli varchar(50);
DECLARE bag int;
DECLARE brg int;
DECLARE qty int;
DECLARE beli int;
DECLARE net int;
DECLARE oldbeli int;
DECLARE oldnet int;
DECLARE updhrg int;
DECLARE ket varchar(100);
DECLARE idsisa int;
DECLARE qtyterima int;
DECLARE qtysisa int;
DECLARE no_more_rows BOOLEAN;
DECLARE loop_cntr INT DEFAULT 0;
DECLARE num_rows INT DEFAULT 0;
DECLARE hitung CURSOR FOR
SELECT
aptlog_orderterima.corp,
aptlog_orderterima.idsupplier,
aptlog_orderterima.faktur,
aptlog_orderterima.idpetugas,
aptlog_supplier.supplier,
aptlog_orderterima.idbagian,
aptlog_orderterimadetail.idbarang,
aptlog_orderterimadetail.beli,
aptlog_orderterimadetail.net,
aptlog_orderterimadetail.qty,
aptlog_barang.beli,
aptlog_barang.net,
aptlog_barang.updatehrg,
CONCAT(aptlog_orderterima.faktur,' From : ',aptlog_supplier.supplier)
FROM
aptlog_orderterima
RIGHT OUTER JOIN aptlog_orderterimadetail ON (aptlog_orderterima.id = aptlog_orderterimadetail.idterima)
LEFT OUTER JOIN aptlog_supplier ON (aptlog_orderterima.idsupplier = aptlog_supplier.id)
LEFT OUTER JOIN aptlog_barang ON (aptlog_orderterimadetail.idbarang = aptlog_barang.id)
WHERE
aptlog_orderterima.id = id;
DECLARE sisaorder CURSOR FOR
SELECT
aptlog_orderdetail.id,
aptlog_orderdetail.qtyterima,
aptlog_orderdetail.sisa
FROM
aptlog_orderdetail
LEFT OUTER JOIN aptlog_order ON (aptlog_orderdetail.idorder = aptlog_order.id)
WHERE
aptlog_order.corp=cor AND
aptlog_order.stat=2 AND
aptlog_order.idsupplier=sup AND
CAST(aptlog_order.waktu AS DATE) >= CURDATE()-(SELECT pengadaan_param.nilai FROM pengadaan_param WHERE pengadaan_param.id=2) AND
aptlog_orderdetail.sisa<>0 AND
aptlog_orderdetail.idbarang=brg
ORDER BY
aptlog_order.waktu
LIMIT 1;
DECLARE CONTINUE HANDLER FOR NOT FOUND
SET no_more_rows = TRUE;
OPEN hitung;
SELECT FOUND_ROWS() INTO num_rows;
the_loop: LOOP
FETCH hitung INTO cor, sup, faktur, ptgs, suppli, bag, brg, beli, net, qty, oldbeli, oldnet, updhrg, ket;
IF no_more_rows THEN CLOSE hitung; LEAVE the_loop;
END IF;
SET #awal = (SELECT aptlog_stok.qty FROM aptlog_stok WHERE corp=cor AND idbarang=brg AND idbagian=bag);
IF #awal IS NOT NULL THEN
UPDATE aptlog_stok SET aptlog_stok.qty = #awal + qty
WHERE corp=cor AND idbarang=brg AND idbagian=bag;
INSERT INTO aptlog_kartustok(waktu, corp, idbagian, idbarang, qtymasuk, qtykeluar, qtysisa, idpetugas, ket)
VALUES (now(), cor, bag, brg, qty, 0, #awal + qty, ptgs, ket); ELSE
INSERT INTO aptlog_stok(corp, idbarang, idbagian, qty)
VALUES (cor, brg, bag, qty);
INSERT INTO aptlog_kartustok(waktu, corp, idbagian, idbarang, qtymasuk, qtykeluar, qtysisa, idpetugas, ket)
VALUES (now(), cor, bag, brg, qty, 0, qty, ptgs, ket);
END IF;
IF updhrg=0 THEN
UPDATE aptlog_barang SET
aptlog_barang.beli=beli,
aptlog_barang.net=net,
aptlog_barang.updatehrg=1,
aptlog_barang.ubahharga=ket,
aptlog_barang.waktuubah=now(),
aptlog_barang.idpetugasubah=ptgs
WHERE
aptlog_barang.id=brg; ELSE
IF (updhrg=1) AND (beli > oldbeli) THEN
UPDATE aptlog_barang SET
aptlog_barang.beli=beli,
aptlog_barang.belilama=oldbeli,
aptlog_barang.net=net,
aptlog_barang.netlama=oldnet,
aptlog_barang.ubahharga=ket,
aptlog_barang.waktuubah=now(),
aptlog_barang.idpetugasubah=ptgs
WHERE
aptlog_barang.id=brg; END IF;
END IF;
SET #qty=qty;
sisa_order: LOOP
OPEN sisaorder;
FETCH sisaorder INTO idsisa, qtyterima, qtysisa;
IF #qty=0 THEN CLOSE sisaorder; LEAVE sisa_order;
END IF;
IF #qty <> 0 THEN
IF qtysisa > #qty THEN
UPDATE aptlog_orderdetail SET
aptlog_orderdetail.qtyterima=qtyterima+#qty,
aptlog_orderdetail.sisa=qtysisa-#qty
WHERE
aptlog_orderdetail.id=idsisa;
SET #qty=0;
ELSE
UPDATE aptlog_orderdetail SET
aptlog_orderdetail.qtyterima=qtyterima+qtysisa,
aptlog_orderdetail.sisa=0
WHERE
aptlog_orderdetail.id=idsisa;
SET #qty = #qty-qtysisa;
END IF;
END IF;
CLOSE sisaorder;
END LOOP sisa_order;
SET loop_cntr = loop_cntr + 1;
END LOOP the_loop;
END');
My question :
The second loop work perfectly, but the first loop just work once.
But if I remove this line "CAST(aptlog_order.waktu AS DATE) >= CURDATE()-(SELECT pengadaan_param.nilai FROM pengadaan_param WHERE pengadaan_param.id=2) AND" from sisaorder all loop work perfectly...
So can anybody help me?
Stored procedure:
CREATE PROCEDURE lead_to_loan(xReffID_list text)
I want to use this xReffID_list variable in a select statement as
SELECT * FROM XXXX where xreffID IN (xReffID_list);
but the xreffID is a int Variable
How Can I use xReffID_list text which is a string of comma separated numbers in the INcondition for int variables ?
Stored procedure:
DELIMITER $$
DROP PROCEDURE IF EXISTS lead_to_loan$$
CREATE PROCEDURE lead_to_loan(XRefID_list text)
BEGIN
DECLARE loanCount int(11) default 0;
DECLARE matchCount int(11) default 0;
DECLARE loan_XRefID int(11);
DECLARE loan_LEADS360ID int(11);
DECLARE loan_email varchar(100);
DECLARE loan_phone varchar(30);
DECLARE loan_cellphone varchar(20);
DECLARE loan_workphone varchar(20);
DECLARE loan_closeDate datetime;
DECLARE loan_FundedDate datetime;
DECLARE lead_id int(11);
DECLARE lead_RefId varchar(100);
DECLARE lead_Email varchar(100);
DECLARE lead_DayPhone varchar(50);
DECLARE lead_EveningPhone varchar(20);
DECLARE lead_Cellphone varchar(20);
DECLARE lead_DateAdded varchar(30);
DECLARE done boolean default false;
DECLARE startTime datetime;
DECLARE cursor_loanDetail CURSOR FOR
SELECT XRefID,LEADS360ID,email,phone,cellphone,workphone,closeDate,FundedDate
FROM fsbcorponline.view_loandetail where find_in_set(XRefID, XRefID_list) > 0;
DECLARE cursor_loanMatchLeads CURSOR FOR
SELECT id,RefId,Email,DayPhone,EveningPhone,Cellphone,DateAdded
FROM fsbcorponline.leads360leads
WHERE RefId !="" AND RefId IS NOT NULL AND RefId =loan_LEADS360ID AND loan_LEADS360ID>0 OR
Email !="" AND Email IS NOT NULL AND Email =loan_email OR
DayPhone !="" AND DayPhone IS NOT NULL AND DayPhone = loan_workphone OR
EveningPhone !="" AND EveningPhone IS NOT NULL AND EveningPhone= loan_phone OR
Cellphone !="" AND Cellphone IS NOT NULL AND Cellphone =loan_cellphone;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
set startTime = now();
OPEN cursor_loanDetail;
cursor_loanDetail_loop: loop
fetch cursor_loanDetail into loan_XRefID,loan_LEADS360ID,loan_email,loan_phone,loan_cellphone,loan_workphone,loan_closeDate,loan_FundedDate;
if done then
set done = false;
leave cursor_loanDetail_loop;
END if;
SET loanCount = loanCount+1;
OPEN cursor_loanMatchLeads;
cursor_loanMatchLeads_loop: loop
fetch cursor_loanMatchLeads into lead_id,lead_RefId,lead_Email,lead_DayPhone,lead_EveningPhone,lead_Cellphone,lead_DateAdded;
if done then
set done = false;
leave cursor_loanMatchLeads_loop;
END if;
SET matchCount = matchCount+1;
INSERT INTO `fsbcorponline`.`leads_to_loan`(`lead_id`,`lead_RefId`,`lead_Email`,`lead_DayPhone`,`lead_EveningPhone`,`lead_Cellphone`,`lead_DateAdded`,`loan_XRefID`,`loan_LEADS360ID`,`loan_email`,`loan_phone`,`loan_cellphone`,`loan_workphone`,`loan_closeDate`,`loan_FundedDate`)
VALUES(lead_id,lead_RefId,lead_Email,lead_DayPhone,lead_EveningPhone,lead_Cellphone,lead_DateAdded,loan_XRefID,loan_LEADS360ID,loan_email,loan_phone,loan_cellphone,loan_workphone,loan_closeDate,loan_FundedDate)
ON duplicate key update loan_updateCount = loan_updateCount +1 ;
leave cursor_loanMatchLeads_loop;
END loop cursor_loanMatchLeads_loop;
CLOSE cursor_loanMatchLeads;
END loop cursor_loanDetail_loop;
close cursor_loanDetail;
INSERT INTO `fsbcorponline`.`log`(`processName`,`pageName`,`path`,`status`,`note`,`processStartTime`,`processEndTime`)
VALUES('Store Procedure','Lead_to_Loan','Database','1',CONCAT('Loan Matches ',matchCount,' of total ',loanCount),startTime,now());
END$$
DELIMITER ;
You can use find_in_set to do this:
SELECT * FROM XXXX WHERE find_in_set(xreffID, xreffID_list) > 0
Hey you can use cast() function available with Mysql
http://dev.mysql.com/doc/refman/5.0/en/cast-functions.html#function_cast
Hope this will help you.