MySQL syntax error with declarations - mysql

I am trying to create a transaction procedure in MySQL and I keep receiving the following syntax error which is occurring in my variable declarations:
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 ';
DECLARE emp_duplicate INT DEFAULT 0;
DECLARE old_empnum INT DEFAULT 0;
DECL' at line 6
Below is my procedure:
DELIMITER $$
DROP PROCEDURE IF EXISTS new_employee$$
CREATE PROCEDURE new_employee(in_Fname VARCHAR(15),in_Lname VARCHAR(15),
in_hire DATE, in_DOB DATE, in_sal Numeric(7,2))
BEGIN
DECLARE out_message VARCHAR;
DECLARE emp_duplicate INT DEFAULT 0;
DECLARE old_empnum INT DEFAULT 0;
DECLARE out_empnum INT DEFAULT 0;
DECLARE time_created DATETIME;
DECLARE user_var VARCHAR;
DECLARE age_var Int DEFAULT 0;
START TRANSACTION;
Select MAX(Empno)
Into old_empnum
From emp;
Select COUNT(*)
Into emp_duplicate
From emp
Where (in_Fname=Fname AND in_Lname=Lname AND in_hire=HireDate AND in_DOB=DOB);
IF emp_duplicate=0 THEN
SET out_message = 'New employee update successful';
SET out_empnum = old_empnum + 1;
SET time_created = CURRENT_TIMESTAMP();
SET user_var = USER();
SET age_var = DATEDIFF(CURRENT_DATE,in_DOB);
INSERT INTO emp(Empno,Fname,Lname,HireDate,DOB,SAL)
VALUES(in_Fname,in_Lname,in_hire,in_DOB,in_sal);
INSERT INTO log(Empno,DateCreated,Who)
VALUES(out_empnum,time_created,user_var);
SELECT out_message;
SELECT Empno, Fname, Lname, DATEDIFF(CURRENT_DATE,DOB), HireDate
From emp;
ELSE
SET out_message = 'Employee already exists';
SELECT out_message;
END IF;
COMMIT;
END$$
DELIMITER ;
I am using cmd and notepad to execute my code (just in case that's helpful). For the life of me, I cannot see the error with my declarations?????

you need to define the VARCHAR size like this
DECLARE out_message VARCHAR(20);
try this
BEGIN
DECLARE out_message VARCHAR(20); // // varchar size here
DECLARE emp_duplicate INT DEFAULT 0;
DECLARE old_empnum INT DEFAULT 0;
DECLARE out_empnum INT DEFAULT 0;
DECLARE time_created DATETIME;
DECLARE user_var VARCHAR(20); // varchar size here
DECLARE age_var Int DEFAULT 0;

you forget to datatype size for DECLARE out_message VARCHAR (30) and DECLARE user_var VARCHAR(30);
DECLARE out_message VARCHAR (30); <------------- here
DECLARE emp_duplicate INT DEFAULT 0;
DECLARE old_empnum INT DEFAULT 0;
DECLARE out_empnum INT DEFAULT 0;
DECLARE time_created DATETIME;
DECLARE user_var VARCHAR(30); <------------- here
DECLARE age_var Int DEFAULT 0;
In insert statement you are missing value for Empno
INSERT INTO emp(Empno,Fname,Lname,HireDate,DOB,SAL)
VALUES(in_Fname,in_Lname,in_hire,in_DOB,in_sal);

Related

How to make TWO loops in a UDF at mysql

similar to StackOverflowPosting I would like to calculate the Levenshtein Distance for a m x n matrix consisting of TITLE1 and TITLE2.
My Levenshtein Functions works fine and is from here: LD
But my Question is how can I loop through the m x n in a UDF?
The Result should be a table with m x n rows with LD, TITLE1 and TITLE2.
I have done this - BUT I ALWAYS GET AN ERROR
1338 Cursor Declaration after Handler Declaration
My UDF looks like this:
BEGIN
DECLARE bDone INT;
DECLARE bDone1 INT;
DECLARE var2 varCHAR(255); -- or approriate type
DECLARE Var1 INT;
DECLARE c1Var1 VARCHAR(250);
DECLARE curs CURSOR FOR SELECT recid as BIOTIrecid, replace(replace(BIOGRAPHYTITLE," [in SCOPUS]",""),"[SIMILAR]","") as bioti FROM BIO ;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET bDone = 1;
DECLARE curs1 CURSOR FOR SELECT trim(concat(scopus.Titel," ",scopus.Untertitel)) as scopusti FROM scopus ;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET bDone = 1;
DROP TABLE IF EXISTS LDResults;
CREATE TABLE `LDResults` (
`BIOGRAPHYTITLE` varchar(255) DEFAULT NULL,
`recid` int(11) NOT NULL AUTO_INCREMENT,
`BIOTIrecid` int(11) default NULL,
`LD` varchar(255) DEFAULT NULL,
`ScopusTI` varchar(255) DEFAULT NULL,
PRIMARY KEY (`recid`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
OPEN curs1;
SET bDone1 = 0;
#---------------- run all rows for scopusti
REPEAT
FETCH curs1 into c1var1;
#-----------------------------------------
OPEN curs;
SET bDone = 0;
#----- run all COLUMNs for biographytitle
REPEAT
FETCH curs INTO var1, var2;
INSERT INTO LDResults (`BIOGRAPHYTITLE`, `BIOTIrecid`, `LD`, `ScopusTI`) VALUES (var2, var1, LEVENSHTEIN(var2,c1var1), c1var1);
UNTIL bDone END REPEAT;
#--------------------------------------------
CLOSE curs;
UNTIL bDone1 END REPEAT;
CLOSE curs1;
SELECT * FROM LDResults;
END
Is my way to solve this problem sophisticated or could this be done on a more faster and better solution ?
Thanks for all advices.
EDIT:
I could make it with a counter here: Any comments?
BEGIN
-- DECLARE bDone INT;
-- DECLARE bDone1 INT;
DECLARE i INT;
DECLARE var2 varCHAR(255); -- or approriate type
DECLARE Var1 INT;
DECLARE cVar1 VARCHAR(250);
DECLARE curs1 CURSOR FOR SELECT trim(concat(t.Titel," ",t.Untertitel)) as scopusti FROM tscopus t ;
DECLARE curs CURSOR FOR SELECT recid as BIOTIrecid, replace(replace(BIOGRAPHYTITLE," [in SCOPUS]",""),"[SIMILAR]","") as bioti FROM tBIO ;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET bDone = 1;
#DECLARE curs1 CURSOR FOR SELECT trim(concat(t.Titel," ",t.Untertitel)) as scopusti FROM tscopus t ;
#DECLARE CONTINUE HANDLER FOR NOT FOUND SET bDone = 1;
DROP TABLE IF EXISTS LDResults;
CREATE TABLE `LDResults` (
`BIOGRAPHYTITLE` varchar(255) DEFAULT NULL,
`recid` int(11) NOT NULL AUTO_INCREMENT,
`BIOTIrecid` int(11) default NULL,
`LD` varchar(255) DEFAULT NULL,
`ScopusTI` varchar(255) DEFAULT NULL,
PRIMARY KEY (`recid`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
OPEN curs1;
SET i = 0;
SET bDone1 = 0;
-- ---------------- run all rows for scopusti
REPEAT
FETCH curs1 into cvar1;
set i=(i+1);
-- -----------------------------------------
OPEN curs;
SET bDone = 0;
-- ----- run all COLUMNs for biographytitle
REPEAT
FETCH curs INTO var1, var2;
INSERT INTO LDResults (`BIOGRAPHYTITLE`, `BIOTIrecid`, `LD`, `ScopusTI`) VALUES (var2, var1, LEVENSHTEIN(var2,cvar1), cvar1);
UNTIL bDone END REPEAT;
-- --------------------------------------------
CLOSE curs;
UNTIL (i >= 2) END REPEAT;
CLOSE curs1;
SELECT * FROM LDResults;
END
I mean you can do it by next way useng CROSS JOIN without loops in your code. CROSS JOIN by definition return product of two tables rows result.
So you can use this result and after some data manipulation insert the result into new table like:
DROP TABLE IF EXISTS LDResults;
CREATE TABLE `LDResults` (
`BIOGRAPHYTITLE` varchar(255) DEFAULT NULL,
`recid` int(11) NOT NULL AUTO_INCREMENT,
`BIOTIrecid` int(11) default NULL,
`LD` varchar(255) DEFAULT NULL,
`ScopusTI` varchar(255) DEFAULT NULL,
PRIMARY KEY (`recid`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
INSERT INTO LDResults (`BIOGRAPHYTITLE`, `BIOTIrecid`, `LD`, `ScopusTI`)
SELECT bioti, BIOTIrecid, LEVENSHTEIN(bioti,scopusti), scopusti
FROM (
SELECT
replace(replace(BIO.BIOGRAPHYTITLE," [in SCOPUS]",""),"[SIMILAR]","") as bioti,
BIO.recid as BIOTIrecid,
trim(concat(scopus.Titel," ",scopus.Untertitel)) as scopusti
FROM scopus
CROSS JOIN BIO
) tbl;

ERROR 1064 (42000): While Declaring a Cursor

I am Trying to create stored procedure in MYSQLand getting below error.
I googled about it but no solution found please help me in this.
DELIMITER //
CREATE OR REPLACE PROCEDURE P_PROCESS_USER_STG ( OUT O_error_msg VARCHAR(3000),
OUT O_status VARCHAR(300),
IN I_uploaded_by INT (10))
BEGIN
declare L_program_name VARCHAR(100);
declare L_login_id INT(10) ;
declare L_password VARCHAR(100);
declare L_first_name VARCHAR(100);
declare L_last_name VARCHAR(100);
declare L_privilege_group_id INT(10) ;
declare L_group_id INT(10) ;
declare L_message VARCHAR(100);
declare L_date_of_upload TIMESTAMP ;
declare L_date_of_update TIMESTAMP ;
declare L_uploaded_by INT(10) ;
declare L_status VARCHAR(10) ;
declare L_error_msg VARCHAR(100),
declare L_finished INT(1) DEFAULT 0;
declare C_user_stg CURSOR FOR
SELECT LOGIN_ID,
PASSWORD,
FIRST_NAME,
LAST_NAME,
PRIVILEGE_GROUP_ID,
GROUP_ID
FROM uploaded_user_stg
where UPLOADED_BY = I_uploaded_by
and status in ( 'NEW' , 'UPDATE' );
declare CONTINUE HANDLER
FOR NOT FOUND SET L_finished = 1;
OPEN C_user_stg;
get_user: LOOP
FETCH C_user_stg INTO L_login_id ,
L_password ,
L_first_name ,
L_last_name ,
L_privilege_group_id,
L_group_id ;
IF L_finished = 1 THEN
LEAVE get_user;
END IF;
-- build email list
CALL P_CREATE_USER ( L_message ,
L_status ,
L_login_id ,
L_password ,
L_first_name,
L_last_name ,
L_privilege_group_id,
L_group_id )
UPDATE uploaded_user_stg
SET status = L_status,
error_msg = L_message
date_of_update = now();
where login_id = L_login_id;
END LOOP get_email;
CLOSE get_user;
END//
DELIMITER ;
I am getting Below error :
ERROR 1064 (42000): You have an error in your SQL syntax; check the
manual that on for the right syntax to use near '
declare L_finished INT(1) DEFAULT 0;
declare C_' at line 18
Change this from:
declare L_error_msg VARCHAR(100),
to
declare L_error_msg VARCHAR(100);

MySql Error Code: 1064

I can't find the error. can you help me?
DELIMITER $$
CREATE PROCEDURE ReadBalance (IN mes INT,IN anio INT)
BEGIN
DECLARE rowid INT;
DECLARE entity INT;
DECLARE grupo VARCHAR(100);
DECLARE relacion INT;
DECLARE ini INT;
DECLARE fin INT;
DECLARE tipo INT;
DECLARE detalle INT;
DECLARE ctain INT;
DECLARE ctaen INT;
DECLARE debe DECIMAL(17,2);
DECLARE haber DECIMAL(17,2);
DECLARE saldo DECIMAL(17,2);
DECLARE done INT DEFAULT 0;
CREATE TEMPORARY TABLE Balance (
rowid INT NOT NULL
, entity TINYINT NOT NULL DEFAULT 0
, grupo VARCHAR(150) NOT NULL
, relacion INT UNSIGNED NOT NULL DEFAULT 0
, ini INT UNSIGNED NOT NULL DEFAULT 0
, fin INT UNSIGNED NOT NULL DEFAULT 0
, tipo INT UNSIGNED NOT NULL DEFAULT 1
, detalle INT UNSIGNED NOT NULL DEFAULT 0
, ctain INT UNSIGNED NOT NULL DEFAULT 0
, ctaen INT UNSIGNED NOT NULL DEFAULT 0
, debe DECIMAL(12,2) NOT NULL DEFAULT 0.00
, haber DECIMAL(12,2) NOT NULL DEFAULT 0.00
, saldo DECIMAL(12,2) NOT NULL DEFAULT 0.00
) ENGINE=MEMORY;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
DECLARE cur1 CURSOR FOR
SELECT
g.`rowid`,
g.`entity`,
g.`grupo`,
g.`fk_codagr_rel`,
g.`fk_codagr_ini`,
g.`fk_codagr_fin`,
g.`tipo_edo_financiero`,
g.`Detalle`,
ctai.`cta`,
ctae.`cta`
FROM
`llx_contab_grupos` g
INNER JOIN `llx_contab_cat_ctas` ctai
ON ctai.`rowid` = g.`fk_codagr_ini`
INNER JOIN llx_contab_cat_ctas ctae
ON ctae.`rowid` = g.`fk_codagr_fin` ;
OPEN cur1;
read_loop: LOOP
FETCH cur1 INTO rowid, entity, grupo,relacion, ini,fin,tipo,detalle,ctain,ctaen;
IF done =1THEN
LEAVE read_loop;
END IF;
SELECT debe := SUM(d.`debe`), haber:= SUM(d.`haber`) FROM `llx_contab_polizasdet` d
INNER JOIN llx_contab_polizas e ON e.`rowid` = d.`fk_poliza`
WHERE e.`anio` = anio
AND e.`mes` = mes
AND d.`cuenta` >= ctain
AND d.`cuenta` <= ctaen
;
saldo = debe-haber;
INSERT INTO Balance (
rowid,
entity,
grupo,
relacion,
ini,
fin,
tipo,
detalle,
ctain,
ctaen,
debe,
haber,
saldo
)
VALUES
(
rowid,
entity,
grupo,
relacion,
ini,
fin,
tipo,
detalle,
ctain,
ctaen,
debe,
haber,
saldo
) ;
END LOOP read_loop;
CLOSE cur1;
SELECT * FROM Balance;
END$$
DELIMITER ;
error message:
1 queries executed, 0 success, 1 errors, 0 warnings
Query:
CREATE PROCEDURE ReadBalance (IN mes INT,IN anio INT) BEGIN DECLARE rowid INT;
DECLARE entity INT;
DECLARE grupo VARCHAR(100); D...
Error Code: 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 'DECLARE CONTINUE HANDLER FOR NOT FOUND SET done =
1;
DECLARE cur1 CURSOR FOR
SE' at line 32
Execution Time : 0 sec
Transfer Time : 0 sec
Total Time : 0 sec
I create this, and works correctly;
DELIMITER $$
USE `tindustrial`$$
DROP PROCEDURE IF EXISTS `Cur`$$
CREATE DEFINER = `root` #`localhost` PROCEDURE `Cur` ()
BEGIN
DECLARE rowid INT ;
DECLARE entity INT ;
DECLARE grupo VARCHAR (100) ;
DECLARE relacion INT ;
DECLARE ini INT ;
DECLARE fin INT ;
DECLARE tipo INT ;
DECLARE detalle INT ;
DECLARE ctain INT ;
DECLARE ctaen INT ;
DECLARE debe DECIMAL (17, 2) ;
DECLARE haber DECIMAL (17, 2) ;
DECLARE saldo DECIMAL (17, 2) ;
DECLARE no_more_rows BOOLEAN ;
DECLARE cur_B CURSOR FOR
SELECT
g.rowid,
g.entity,
g.grupo,
g.fk_codagr_rel,
g.fk_codagr_ini,
g.fk_codagr_fin,
g.tipo_edo_financiero,
g.Detalle,
ctai.cta,
ctae.cta
FROM
llx_contab_grupos g
INNER JOIN llx_contab_cat_ctas ctai
ON ctai.rowid = g.fk_codagr_ini
INNER JOIN llx_contab_cat_ctas ctae
ON ctae.rowid = g.fk_codagr_fin ;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET no_more_rows = 1 ;
CREATE TEMPORARY TABLE Balance (
rowid INT NOT NULL,
entity TINYINT NOT NULL DEFAULT 0,
grupo VARCHAR (150) NOT NULL,
relacion INT UNSIGNED NOT NULL DEFAULT 0,
ini INT UNSIGNED NOT NULL DEFAULT 0,
fin INT UNSIGNED NOT NULL DEFAULT 0,
tipo INT UNSIGNED NOT NULL DEFAULT 1,
detalle INT UNSIGNED NOT NULL DEFAULT 0,
ctain INT UNSIGNED NOT NULL DEFAULT 0,
ctaen INT UNSIGNED NOT NULL DEFAULT 0,
debe DECIMAL (12, 2) NOT NULL DEFAULT 0.0,
haber DECIMAL (12, 2) NOT NULL DEFAULT 0.0,
saldo DECIMAL (12, 2) NOT NULL DEFAULT 0.0
) ENGINE=MEMORY;
OPEN cur_b ;
the_loop :
LOOP
FETCH cur_B INTO rowid,
entity,
grupo,
relacion,
ini,
fin,
tipo,
detalle,
ctain,
ctaen ;
IF no_more_rows
THEN CLOSE cur_b ;
LEAVE the_loop ;
END IF ;
END LOOP the_loop ;
CLOSE cur_b ;
TRUNCATE TABLE Balance ;
END $$
DELIMITER ;

nested cursor in mysql but showing syntax error

DELIMITER $$
USE `g4winners2`$$
DROP PROCEDURE IF EXISTS `wagerMigration`$$
CREATE DEFINER=`root`#`localhost` PROCEDURE `wagerMigration`()
BEGIN
DECLARE tbrace_done, tbrunner_done BOOLEAN DEFAULT FALSE;
DECLARE race_card_id INT(10);
DECLARE race_number INT(10);
DECLARE day_evening VARCHAR(10) ;
DECLARE locale_type VARCHAR(50) ;
DECLARE course_surface VARCHAR(8) ;
DECLARE distance_unit VARCHAR(8) ;
DECLARE race_type VARCHAR(50) ;
DECLARE sex_restriction VARCHAR(8) ;
DECLARE age_restriction VARCHAR(8) ;
DECLARE purse_usa DECIMAL(18,2) ;
DECLARE maximum_claim_price DECIMAL(9,2) ;
DECLARE race_name VARCHAR(120) ;
DECLARE race_condition VARCHAR(255) ;
DECLARE condition_text TEXT ;
DECLARE post_time TIME ;
DECLARE race_date TIMESTAMP;
DECLARE is_active TINYINT(1) ;
DECLARE race_status_type INT(11) ;
DECLARE gait VARCHAR(50) ;
DECLARE field_size SMALLINT(6);
DECLARE weather VARCHAR(25);
DECLARE comments VARCHAR(128);
DECLARE odds_updated DATETIME;
DECLARE pools_updated DATETIME;
DECLARE win_pool_total INT(11);
DECLARE plc_pool_total INT(11);
DECLARE shw_pool_total INT(11);
declare horse_name varchar(50);
declare foaling_area char(3);
declare color varchar(255);
declare sex varchar(255);
declare breeder_name varchar(255);
declare sire_name varchar(255);
declare post_position int(10);
declare program_number varchar(255);
declare weight_carried int(10);
declare scratch_indicator varchar(255);
declare trainer_first_name varchar(255);
declare owner_name varchar(255) ;
declare jockey_first_name varchar(255);
declare odds varchar(255) ;
declare owner_silks varchar(255);
declare live_odds varchar(255);
declare is_visible tinyint(10);
declare finish_position smallint(6);
declare dead_heat_flag smallint(6);
declare distance_from_winner smallint(6);
declare win_pool int(11);
declare plc_pool int(11);
declare shw_pool int(11);
DECLARE curRace CURSOR FOR SELECT ee.event_number,"wer",'en_us',ee.surface,ee.distance,ee.race_type_text,ee.sex_restriction ,ee.age_restriction,
ee.purse,ee.max_claiming_price,ee.event_name,ee.race_conditions1,ee.track_conditions,ee.post_time,ee.raceday,ee.confirmed_flag,ee.status,ee.gait,
ee.field_size,ee.weather,ee.comments,ee.odds_updated,ee.pools_updated,ee.win_pool_total,ee.plc_pool_total,ee.shw_pool_total
FROM ebet.events ee ,ebet.race_meetings trc
WHERE trc.meeting_number=ee.meeting_number
AND trc.raceday=ee.raceday;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET tbrace_done = TRUE;
OPEN curRace;
cur_race_loop: LOOP
FETCH FROM curRace INTO race_number ,day_evening ,locale_type,course_surface,distance_unit,race_type,sex_restriction ,age_restriction
,purse_usa ,maximum_claim_price ,race_name ,race_condition ,condition_text
,post_time ,race_date ,is_active ,race_status_type ,gait
,field_size,weather,comments,odds_updated,pools_updated,win_pool_total,plc_pool_total,shw_pool_total;
IF tbrace_done THEN
CLOSE curRace;
LEAVE cur_race_loop;
END IF;
SET FOREIGN_KEY_CHECKS=0;
INSERT INTO g4winners2.tb_races(race_number ,day_evening ,locale_type,course_surface,distance_unit,race_type,sex_restriction ,age_restriction
,purse_usa ,maximum_claim_price ,race_name ,race_condition ,condition_text
,post_time ,race_date ,is_active ,race_status_type ,gait
,field_size,weather,comments,odds_updated,pools_updated,win_pool_total,plc_pool_total,shw_pool_total)
VALUES (race_number ,day_evening ,locale_type,course_surface,distance_unit,race_type,sex_restriction ,age_restriction
,purse_usa ,maximum_claim_price ,race_name ,race_condition ,condition_text
,post_time ,race_date ,is_active ,race_status_type ,gait
,field_size,weather,comments,odds_updated,pools_updated,win_pool_total,plc_pool_total,shw_pool_total);
SET FOREIGN_KEY_CHECKS=1;
SET #ID:=(SELECT LAST_INSERT_ID());
SELECT CONCAT ("Result :**", #ID, " ") AS '';
SET FOREIGN_KEY_CHECKS=0;
BLOCK2: BEGIN
DECLARE curRunner CURSOR FOR SELECT er.runner_name,er.area_foaled,er.color,er.sex,er.breeder,er.sire,er.post_position,er.program_number ,er.weight,
er.scratched_flag,er.trainer,er.owner,er.jockey,er.morning_line_odds,er.silks,er.current_odds,'1', er.finish_position,er.dead_heat_flag
,er.distance_from_winner,er.win_pool,er.plc_pool,er.shw_pool FROM ebet.runners er ,ebet.events ee
WHERE
ee.meeting_number=er.meeting_number
AND ee.event_number=er.event_number
AND ee.raceday=er.raceday;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET tbrunner_done = TRUE;
OPEN curRunner;
cur_runner_loop: LOOP
FETCH curRunner INTO horse_name,foaling_area,color,sex,breeder_name,sire_name,post_position,program_number,weight_carried,scratch_indicator,trainer_first_name,owner_name,jockey_first_name,odds,owner_silks,live_odds,is_visible,finish_position,dead_heat_flag,distance_from_winner,win_pool,plc_pool,shw_pool;
IF tbrace_done THEN
set tbrace_done = false;
CLOSE curRunner;
LEAVE cur_runner_loop;
END IF;
INSERT INTO g4winners2.tb_race_runners(race_id,horse_name,foaling_area,color,sex,breeder_name,sire_name,post_position,program_number ,
weight_carried,scratch_indicator ,trainer_first_name ,owner_name ,jockey_first_name,odds ,owner_silks ,live_odds ,is_visible
,finish_position,dead_heat_flag,distance_from_winner,win_pool,plc_pool,shw_pool
) values(#ID,horse_name,foaling_area,color,sex,breeder_name,sire_name,post_position,program_number ,
weight_carried,scratch_indicator ,trainer_first_name ,owner_name ,jockey_first_name,odds ,owner_silks ,live_odds ,is_visible
,finish_position,dead_heat_flag,distance_from_winner,win_pool,plc_pool,shw_pool);
END LOOP cur_runner_loop;
END BLOCK2;
END LOOP cur_race_loop;
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 '' at line 118 (0 ms taken)
Could it be a false error as it can not compile as you have no "END" to the overall procedure?. You close out your loops and block, but not the procedure.

Debugging stored procedure but no value return

My applications calls a stored procedure as required by my use case. The stored procedure insert records into two tables related by primary and foreign key constraints.
This means PatientNumber in Visit table must exist in the Patient table.
When I debug this procedure no value is display after setting initial values.
I am new to this, please help.
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[Add_Patient_Visit]
AS
BEGIN TRANSACTION
SET NOCOUNT ON;
declare #Visit_Number Varchar(50)
declare #Prescription_Number Varchar(50)
declare #Visit_Date Datetime = GETDate()
set #Visit_Number = '25684956555'
set #Visit_Date = GETDATE()
set #Prescription_Number = '653214658'
INSERT INTO Visits(Visit_Number, Visit_Date, Patient_Number)
VALUES(#Visit_Number, #Visit_Date, #Patient_Number)
IF ##ERROR <> 0
BEGIN
ROLLBACK
RETURN
END
declare #Patient_Number Varchar(50)
declare #FirstName Varchar(50)
declare #LastName Varchar(50)
declare #Trible Varchar(50)
declare #Gender Varchar(5)
declare #Date_Of_Birth Datetime
INSERT INTO Patient(Patient_Number, FirstName, LastName, Tribe, Gender, Date_Of_Birth)
VALUES (#Patient_Number, #FirstName, #LastName, #Trible, #Gender, #Date_Of_Birth)
IF ##ERROR <> 0
BEGIN
ROLLBACK
RETURN
END
COMMIT
GO
There is a mistake in above procedure. You are using #Patient_Number before declaring, while inserting in table 'Visits'. Declare it in begining, like :
declare #Patient_Number Varchar(50)
declare #Visit_Number Varchar(50)
declare #Prescription_Number Varchar(50)
declare #Visit_Date Datetime = GETDate()
set #Visit_Number = '25684956555'
set #Visit_Date=GETDATE()
set #Prescription_Number='653214658'
Insert into Visits(Visit_Number,Visit_Date,Patient_Number)
Values(#Visit_Number,#Visit_Date,#Patient_Number)
IF ##ERROR <> 0
BEGIN
ROLLBACK
RETURN
END
declare #FirstName Varchar(50)
declare #LastName Varchar(50)
declare #Trible Varchar(50)
declare #Gender Varchar(5)
declare #Date_Of_Birth Datetime
INSERT INTO Patient(Patient_Number,FirstName,LastName,Tribe,Gender,Date_Of_Birth)
VALUES (#Patient_Number,#FirstName,#LastName,#Trible,#Gender,#Date_Of_Birth)
IF ##ERROR <> 0
BEGIN
ROLLBACK
RETURN
END
COMMIT