Ram Eswar
Ram Eswar

Reputation: 37

mysql syntax error while set stored procedure parameter

I written the code for mysql stored procedure it shows syntax error i didn't know what mistake i done. anyone help me please.

DELIMITER $$

DROP PROCEDURE IF EXISTS `aad_adr`.` PROCEDURE MonthlySalesReport(fromdate DATE,todate DATE)` $$
CREATE PROCEDURE `aad_adr`.` PROCEDURE MonthlySalesReport(fromdate DATE,todate DATE)` ()
BEGIN
Declare fd DATE;
Declare ed DATE;
SET fd=fromdate;
SET ed=todate;
WHILE DATE(fd)<=DATE(ed)DO
select bill_master.bill_no,DATE_FORMAT(bill_master.bill_date, '%y/%m/%d') AS 'formatted_date',transaction.product_id,transaction.tax_amount,transaction.amount,transaction.amount-transaction.tax_amount as 'without_tax ',product_master.Product_name,product_master.vat from bill_master inner join transaction on bill_master.bill_no=transaction.bill_no inner join product_master on transaction.product_id=product_master.product_id where vat='14.50' and DATE_FORMAT(bill_master.bill_date, '%y/%m/%d') fd;
SET fd=DATE_ADD(fd,INTERVAL 1 DAY);
END WHILE;
END $$

DELIMITER;

error:

Script line: 4  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 'fd;
SET fd=DATE_ADD(fd,INTERVAL 1 DAY);
END WHILE;
END' at line 8

Upvotes: 1

Views: 110

Answers (2)

Piyush Gupta
Piyush Gupta

Reputation: 2179

Error in your select query you are calling wrong where condition. So Just remove DATE_FORMAT in where clause And need to one more modification just replace DELIMITER; to DELIMITER$$ in last.

Update 1: Modified Valid name of SP.

So Updated Code is:

DELIMITER $$

DROP PROCEDURE IF EXISTS `aad_adr`.`MonthlySalesReport` $$
CREATE PROCEDURE `aad_adr`.`MonthlySalesReport`(IN fromdate DATE,IN todate DATE)
     BEGIN
       DECLARE fd DATE;
       DECLARE ed DATE;
       SET fd=fromdate;
       SET ed=todate;
       WHILE DATE(fd)<=DATE(ed)DO
             SELECT bill_master.bill_no,DATE_FORMAT(bill_master.bill_date, '%y/%m/%d') AS 'formatted_date',transaction.product_id,transaction.tax_amount,transaction.amount,transaction.amount-transaction.tax_amount AS 'without_tax ',product_master.Product_name,product_master.vat FROM bill_master INNER JOIN TRANSACTION ON bill_master.bill_no=transaction.bill_no INNER JOIN product_master ON transaction.product_id=product_master.product_id WHERE vat='14.50' AND bill_master.bill_date=fd;
          SET fd=DATE_ADD(fd,INTERVAL 1 DAY);
       END WHILE;
    END $$
DELIMITER$$

Upvotes: 1

Charif DZ
Charif DZ

Reputation: 14721

First you have two erreur: the first one is the name of PROCEDURE

CREATE PROCEDURE `aad_adr`.` PROCEDURE MonthlySalesReport(fromdate DATE,todate DATE)` ()

--- >

CREATE PROCEDURE `aad_adr`.`MonthlySalesReport`(fromdate DATE,todate DATE)

so you procedure should be like this :

DELIMITER $$
DROP PROCEDURE IF EXISTS `aad_adr`.`MonthlySalesReport`$$
CREATE PROCEDURE `aad_adr`.`MonthlySalesReport`(fromdate DATE,todate DATE)
BEGIN
Declare fd DATE;
Declare ed DATE;
SET fd=fromdate;
SET ed=todate;
WHILE DATE(fd)<=DATE(ed)DO
select 
bill_master.bill_no,
DATE_FORMAT(bill_master.bill_date,'%y/%m/%d') AS 'formatted_date',
transaction.product_id,
transaction.tax_amount,
transaction.amount,
transaction.amount-transaction.tax_amount as 'without_tax ',
product_master.Product_name,
product_master.vat 
from 
bill_master inner join transaction on bill_master.bill_no=transaction.bill_no 
inner join product_master on transaction.product_id=product_master.product_id 
where
vat='14.50' and vat='14.50' and DATE_FORMAT(bill_master.bill_date, '%y/%m/%d');
SET fd=DATE_ADD(fd,INTERVAL 1 DAY);
END WHILE;
END $$
DELIMITER ;

Upvotes: 0

Related Questions