关于 一个存储调用 另外一个 存储(上个月日期)问题
2个存储的代码,分别 call 单独运行是没有问题的,call sp_crosstable() 或者call get_current_date()
代码如下
DROP PROCEDURE IF EXISTS get_current_date;
USE chisheng2019;
DELIMITER &&
CREATE PROCEDURE get_current_date()
BEGIN
SELECT date_format(date_sub(curdate(), interval 1 month),'%Y%m') as date;
END &&
DELIMITER ;
DROP PROCEDURE IF EXISTS sp_crosstable;
SET SESSION GROUP_CONCAT_max_len= 102400;
DELIMITER &&
CREATE PROCEDURE sp_crosstable() reads SQL data
BEGIN
SET @sql_str = NULL;
SELECT
GROUP_CONCAT(DISTINCT(
CONCAT('SUM(IF(date=\'',date,'\',qty,0)) AS ''',date,'''')) order by subptou1.invono ASC )
INTO @sql_str
from
subptou1
inner join subptou2 on subptou2.invono=subptou1.invono
left join subvendor1 on subvendor1.vendorid=subptou1.vendorid
where date_format(subptou1.date,'%Y-%m')= date_format(date_sub(curdate(), interval 1 month),'%Y-%m');
set @sql_str =
CONCAT('SELECT IFNULL(vendor,\'总计\') AS 客户名称,',
@sql_str,
',sum(IFNULL(subptou2.qty,0)) AS 历史总收数量
from
subptou1
inner join subptou2 on subptou2.invono=subptou1.invono
left join subvendor1 on subvendor1.vendorid=subptou1.vendorid
WHERE CONCAT(SUBSTRING(subptou1.date , 1, 4),SUBSTRING(subptou1.date , 6, 2))=202401
GROUP BY vendor WITH ROLLUP;');
PREPARE stmt from @sql_str;
EXECUTE stmt;
DEALLOCATE prepare stmt;
END &&
DELIMITER ;
/*call sp_crosstable*/
/*call get_current_date*/
我现在遇到的问题是,怎样把例子的 202401替换成 call get_current_date ,或者怎样弄?