关于存储过程的问题

老是提示关键字“case”附近有问题,
关键字“END”附近有问题。

CREATE PROCEDURE sp_AdjustProtectNumber
@user_code int,
@protect_manager_no tinyint,
@protect_general_no tinyint,
@protect_senior_no tinyint,
@protect_engineer_no tinyint
AS
declare @right_no tinyint
declare @protect_no tinyint
declare @delete_protect_no int

select @right_no=right_no from t_employee where id=@user_code
if @@rowcount>0
BEGIN
case
when (@right_no=2 or @right_no=3) then @protect_no=@protect_manager_no
when @right_no=10 then @protect_no=@protect_general_no
when @right_no=11 then @protect_no=@protect_senior_no
when @right_no=12 then @protect_no=@protect_engineer_no
end

if EXISTS(select id from t_ponodetail where user_code=@user_code and protect=1)
BEGIN
set @delete_protect_no=@@rowcount-@protect_no
execute ('update t_ponodetail set protect=0 where id in (select top @delete_protect_no id from t_ponodetail where user_code=@user_code and protect=1 order by begin_date)')
END
END
Return

请大家帮我看看是什么问题?谢谢!

---------------------------------------------------------------

CREATE PROCEDURE sp_AdjustProtectNumber
@user_code int,
@protect_manager_no tinyint,
@protect_general_no tinyint,
@protect_senior_no tinyint,
@protect_engineer_no tinyint
AS
declare @right_no tinyint
declare @protect_no tinyint
declare @delete_protect_no int

select @right_no=right_no from t_employee where id=@user_code
if @@rowcount>0
BEGIN
select @protect_no=case
when (@right_no=2 or @right_no=3) then @protect_manager_no
when @right_no=10 then @protect_general_no
when @right_no=11 then @protect_senior_no
when @right_no=12 then @protect_engineer_no
end

if EXISTS(select id from t_ponodetail where user_code=@user_code and protect=1)
BEGIN
set @delete_protect_no=@@rowcount-@protect_no
execute ('update t_ponodetail set protect=0 where id in (select top @delete_protect_no id from t_ponodetail where user_code=@user_code and protect=1 order by begin_date)')
END
END
Return

Published At
Categories with Web编程
comments powered by Disqus