Home > database >  Mysql, 1064.
Mysql, 1064.

Time:09-26

Everybody is good, I write a stored procedure, operation time has been an Error, the 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 at line 1 'NULL',

Can you help to look at, I write the table and stored procedure which has a problem, with a few days,,,, thank you first!

DELIMITER $$
The CREATE DEFINER=` catavolt ` @ % ` ` PROCEDURE ` sp_create_timesheet ` (IN p_TechId varchar (10), IN p_Date varchar (10))
The BEGIN
Declare w_last_inserted_record integer;
Declare w_pIx integer;
Declare w_update varchar (21845);
Declare w_where varchar (2048);
Declare w_sql varchar (21845);
Declare w_finished integer;

Declare w_P_Num integer;
Declare w_Service_WON nvarchar (10);
Declare w_Comments nvarchar (200);
Declare w_TotalHours decimal (4, 2);
Declare w_OT_Code nvarchar (10);
Declare w_JobComplete nvarchar (5);




DECLARE cr CURSOR FOR the SELECT ` Service_WON `,
` Comments `, ` TotalHours `, ` OT_Code `, ` JobComplete `

The FROM ` cv_vw_newtransactionsumadmin `
WHERE ` PersonID `=p_TechId and ` OrderDate `=p_Date;
DECLARE the CONTINUE HANDLER FOR the NOT FOUND SET w_finished=1;
The OPEN cr;
The SET SQL_SAFE_UPDATES=0;

The DELETE FROM ` cv_timesheet ` WHERE ` TechName `=p_TechId and ` OrderDate `=p_Date;




INSERT INTO ` cv_timesheet ` (` TechName `, ` OrderDate `)
The SELECT ` PersonID `, ` OrderDate `
The FROM ` Catavolt `. ` cv_vw_newtransactionsumadmin `
Where ` PersonID `=p_TechId and ` OrderDate `=p_Date group by PersonID.


The set w_where=concat (' WHERE TechName=' ' ', p_TechId, 'and OrderDate=' ' ', p_Date, ' ' ' ');


The set w_update=' ';
The set w_pIx=1;
The set w_finished=0;


Get_details: loop
The FETCH cr INTO w_Service_WON, w_Comments w_TotalHours, w_OT_Code, w_JobComplete; -, w_Warehouse
If (w_finished=1 or w_pIx & gt; 10) then
Leave get_details;
end if;

The set w_update=concat (w_update, '` P_Num', w_pIx, '`=' w_pIx, ', ');
Set w_update=concat (w_update, '` WONo', w_pIx,=' ' ', '` w_Service_WON,' ' ', ');
Set w_update=concat (w_update, '` Description', w_pIx,=' ' ', '` w_Comments,' ' ', ');
The set w_update=concat (w_update, '` Hours', w_pIx,' `='w_TotalHours,', ');
Set w_update=concat (w_update, '` WorkCodes', w_pIx,=' ' ', '` w_OT_Code,' ' ', ');
Set w_update=concat (w_update, '` JC_JNC', w_pIx,=' ' ', '` w_JobComplete,' ' ', ');

The set w_pIx=w_pIx + 1;
End loop get_details;

The CLOSE cr;
The set w_update=mid (w_update, 1, (length (w_update) - 2));
The set w_sql=concat (' update ` cv_timesheet ` set ', w_update, ' ', w_where);
The SET @ s=w_sql;
PREPARE stmt1 FROM @ s;
The EXECUTE stmt1;
DEALLOCATE PREPARE stmt1;

END $$
DELIMITER ;




The CREATE TABLE ` cv_timesheet ` (
` id ` int (10) NOT NULL AUTO_INCREMENT,
` P_Num1 ` int (4) the DEFAULT NULL,
` WONo1 ` int (11) the DEFAULT NULL,
` WOLineNumber1 ` varchar (3) the DEFAULT NULL,
DEFAULT NULL ` Customer1 ` varchar (50),
` Description1 ` varchar (1150) the DEFAULT NULL,
` Hours1 ` decimal (4, 2) the DEFAULT NULL,
` WorkCodes1 ` varchar (10) DEFAULT NULL,
` JC_JNC1 ` varchar (5) the DEFAULT NULL,
` WorkCodesNote1 ` varchar (300) the DEFAULT NULL,
` ProjectCodesNote1 ` varchar (300) the DEFAULT NULL,
` P_Num2 ` int (4) the DEFAULT NULL,
` WONo2 ` int (11) the DEFAULT NULL,
` WOLineNumber2 ` varchar (3) the DEFAULT NULL,
DEFAULT NULL ` Customer2 ` varchar (50),
` Description2 ` varchar (1150) the DEFAULT NULL,
` Hours2 ` decimal (4, 2) the DEFAULT NULL,
` WorkCodes2 ` varchar (10) DEFAULT NULL,
` JC_JNC2 ` varchar (5) the DEFAULT NULL,
` WorkCodesNote2 ` varchar (300) the DEFAULT NULL,
` ProjectCodesNote2 ` varchar (300) the DEFAULT NULL,
` P_Num3 ` int (4) the DEFAULT NULL,
` WONo3 ` int (11) the DEFAULT NULL,
` WOLineNumber3 ` varchar (3) the DEFAULT NULL,
DEFAULT NULL ` Customer3 ` varchar (50),
` Description3 ` varchar (1150) the DEFAULT NULL,
` Hours3 ` decimal (4, 2) the DEFAULT NULL,
` WorkCodes3 ` varchar (10) DEFAULT NULL,
` JC_JNC3 ` varchar (5) the DEFAULT NULL,
` WorkCodesNote3 ` varchar (300) the DEFAULT NULL,
` ProjectCodesNote3 ` varchar (300) the DEFAULT NULL,
` P_Num4 ` int (4) the DEFAULT NULL,
` WONo4 ` int (11) the DEFAULT NULL,
` WOLineNumber4 ` varchar (3) the DEFAULT NULL,
DEFAULT NULL ` Customer4 ` varchar (50),
` Description4 ` varchar (1150) the DEFAULT NULL,
` Hours4 ` decimal (4, 2) the DEFAULT NULL,
` WorkCodes4 ` varchar (10) DEFAULT NULL,
` JC_JNC4 ` varchar (5) the DEFAULT NULL,
` WorkCodesNote4 ` varchar (300) the DEFAULT NULL,
` ProjectCodesNote4 ` varchar (300) the DEFAULT NULL,
` P_Num5 ` int (4) the DEFAULT NULL,
` WONo5 ` int (11) the DEFAULT NULL,
` WOLineNumber5 ` varchar (3) the DEFAULT NULL,
DEFAULT NULL ` Customer5 ` varchar (50),
` Description5 ` varchar (1150) the DEFAULT NULL,
` Hours5 ` decimal (4, 2) the DEFAULT NULL,
` WorkCodes5 ` varchar (10) DEFAULT NULL,
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull