Mysql存储过程加个判断条件,急求,好心人帮下忙,谢谢了!
CREATEDEFINER=`root`@`localhost`PROCEDURE`showChildDeptLst`(INrootIdINT,INstatusINT)B...
CREATE DEFINER=`root`@`localhost` PROCEDURE `showChildDeptLst`(IN rootId INT,IN status INT)
BEGIN
CREATE TEMPORARY TABLE IF NOT EXISTS tmpDeptLst
(sno INT PRIMARY KEY AUTO_INCREMENT,id INT,LEVEL INT);
DELETE FROM tmpDeptLst;
CALL createChildDeptLst(rootId,0);
SELECT tmpDeptLst.*,tbl_department.* FROM tmpDeptLst ,tbl_department
where tmpDeptLst.id = tbl_department.ID and PARENT_ID is not null
// while status =1 or 9 do
// and tbl_department.STATUS = status 我想在这里加个判断,怎么加啊
//END WHILE;
ORDER BY tmpDeptLst.sno; 展开
BEGIN
CREATE TEMPORARY TABLE IF NOT EXISTS tmpDeptLst
(sno INT PRIMARY KEY AUTO_INCREMENT,id INT,LEVEL INT);
DELETE FROM tmpDeptLst;
CALL createChildDeptLst(rootId,0);
SELECT tmpDeptLst.*,tbl_department.* FROM tmpDeptLst ,tbl_department
where tmpDeptLst.id = tbl_department.ID and PARENT_ID is not null
// while status =1 or 9 do
// and tbl_department.STATUS = status 我想在这里加个判断,怎么加啊
//END WHILE;
ORDER BY tmpDeptLst.sno; 展开
展开全部
存储过程啊。if status=1 or status=9 then {需要执行的语句} end if;
我想你的意思是判断后再
SELECT tmpDeptLst.*,tbl_department.* FROM tmpDeptLst ,tbl_department
where tmpDeptLst.id = tbl_department.ID and PARENT_ID is not null
后加个and tbl_department.STATUS = status 条件。那么就定义两个varchar变量,第一个比如是A是存
SELECT tmpDeptLst.*,tbl_department.* FROM tmpDeptLst ,tbl_department
where tmpDeptLst.id = tbl_department.ID and PARENT_ID is not null
第二就弄个全局变量或者其他的。
if status=1 or status=9 then
@B=concat(A,'and tbl_department.STATUS = status');
-- 执行sql
prepare create_sql from @B;
EXECUTE create_sql ;
DEALLOCATE prepare create_sql;
end if;
我想你的意思是判断后再
SELECT tmpDeptLst.*,tbl_department.* FROM tmpDeptLst ,tbl_department
where tmpDeptLst.id = tbl_department.ID and PARENT_ID is not null
后加个and tbl_department.STATUS = status 条件。那么就定义两个varchar变量,第一个比如是A是存
SELECT tmpDeptLst.*,tbl_department.* FROM tmpDeptLst ,tbl_department
where tmpDeptLst.id = tbl_department.ID and PARENT_ID is not null
第二就弄个全局变量或者其他的。
if status=1 or status=9 then
@B=concat(A,'and tbl_department.STATUS = status');
-- 执行sql
prepare create_sql from @B;
EXECUTE create_sql ;
DEALLOCATE prepare create_sql;
end if;
来自:求助得到的回答
2013-03-08
展开全部
tbl_department.STATUS = IF( status = 1 OR status = 9 , status , tbl_department.STATUS )
或者
tbl_department.STATUS =
CASE WHEN status = 1 OR status = 9 THEN status
ELSE tbl_department.STATUS END
功能就是 如果 status = 1 OR status = 9 才设置查询的条件。
或者
tbl_department.STATUS =
CASE WHEN status = 1 OR status = 9 THEN status
ELSE tbl_department.STATUS END
功能就是 如果 status = 1 OR status = 9 才设置查询的条件。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询