SQL存储过程语法中循环嵌能套条件吗?如果能嵌套,请问我下面简单的存储过程哪里出现问题了?******申明变量省去了********DECLARE zhcursor CURSOR LOCAL SCROLL
FOR 
select Prod_name,Prov_name from Product
Open zhcursor
fetch next from zhcursor into @prodname,@provname****循环开始****
while @@fetch_status<>-1
begin
set @fenfx=(select fen from Score where (chap='放行') and(Prod_name=@prodname) and(Prov_name=@provname) and (month(Score.Yearmonth)=month (getdate())));
set @fenrc=(select fen from Score where (chap='入库') and(Prod_name=@prodname) and(Prov_name=@provname) and (month(Score.Yearmonth)=month (getdate())));
set @fenxs=(select fen from Score where (chap='线上') and(Prod_name=@prodname) and(Prov_name=@provname) and (month(Score.Yearmonth)=month (getdate())));
set @riqi=(select CONVERT(varchar(10), getDate(),120));
****这里是条件语句****
Select @zhfen=
(Case
When @fenxs=0 Then @fenrc*0.52+@fenfx*0.48
When @fenfx=0 Then @fenrc*0.57+@fenxs*0.43
When @fenrc=0 Then @fenfx*0.55+@fenxs*0.45
When (@fenxs=0 and @fenfx=0) Then @fenrc
When (@fenxs=0 and @fenrc=0) Then @fenfx
When (@fenfx=0 and @fenrc=0) Then @fenxs
Else 
@fenxs*0.25+@fenrc*0.4+@fenfx*0.35
end);
Insert into ZHscore
        (
Yearmonth,
Prov_name,
Prod_name,
score
)
  values
  (
@riqi,
@Provname,
@Prodname,
@zhfen);
fetch next from zhcursor into @prodname,@provname
end
close zhcursor
deallocate zhcursor
end
我试过了,单独使用循环,没问题!单独使用条件也没问题! 两个在一起就不行了?哪里问题啊?