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;
错误:
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
答案 0 :(得分:0)
首先你有两个错误: 第一个是PROCEDURE的名称
CREATE PROCEDURE `aad_adr`.` PROCEDURE MonthlySalesReport(fromdate DATE,todate DATE)` ()
---&gt;
CREATE PROCEDURE `aad_adr`.`MonthlySalesReport`(fromdate DATE,todate DATE)
所以你的程序应该是这样的:
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 ;
答案 1 :(得分:0)
您在选择查询中出错,您在条件中调用错误。因此,只需删除where子句中的DATE_FORMAT,然后再需要进行一次修改,只需将DELIMITER;
替换为DELIMITER$$
。
更新1:修改了SP的有效名称。
所以更新的代码是:
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$$