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?
2
Answers
You are mixing sql serv and mysql , that can not work
But t´you can simply do a
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,