更新:
我使用数据透视表将列名显示为标题根据我的知识一切都很好但是当我尝试添加参数时我收到错误
调用
致电sp_schreport(1,2,' 2014-10-04'); $$
当我试图添加时
"select venue,'null' as first,'null' as second,'null' as third,'null' as fourth from sch_venue where campusid =campid and venueid NOT IN (select venueid from sch_taskassigned where assignedstatus=status AND (sdate BETWEEN taskstartdate AND taskenddate)) UNION"
以及为联合函数获取错误的代码,两个查询列都应该相等,这样我才能使用' null'第一等..
CREATE PROCEDURE sp_schreport(IN campid int,IN status int,IN sdate datetime)
BEGIN
SET @sql = NULL;
SELECT
GROUP_CONCAT(DISTINCT
CONCAT(
'max(CASE WHEN t.session = ''',
t.session,
''' THEN d.department END) AS `',
tagname, '`'
)
) INTO @sql
FROM sch_sessions t;
SET @sql
= CONCAT('select venue,'null' as first,'null' as second,'null' as third,'null' as fourth from sch_venue where campusid =campid and venueid NOT IN (select venueid from sch_taskassigned where assignedstatus=status AND (sdate BETWEEN taskstartdate AND taskenddate))
UNION SELECT v.venueid, ', @sql, '
from sch_taskassigned p
left join sch_sessions t
on p.sid = t.sid inner join sch_venue v on p.venueid=v.venueid inner join sch_departments d where p.campusid=campid and p.assignedstatus=status and (sdate BETWEEN taskstartdate AND taskenddate) group by p.venueid');
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END$$
请在我的程序中找出错误