存储过程:判断太多,如何处理
一个查询的条件判断太多,有没有啥好拌饭。我现在是这样
if(a)
begin
if(a1)
begin
if(a11)
begin
if(a111)
--**----
else
--***---
end
else
if(a111)
--**----
else
--***---
end
end
else
begin
if(a11)
if(a111)
--**----
else
--***---
end
else
if(a111)
--**----
else
--***---
end
end
end
else
begin
if(a1)
begin
if(a11)
begin
if(a111)
--**----
else
--***---
end
else
if(a111)
--**----
else
--***---
end
end
else
begin
if(a11)
if(a111)
--**----
else
--***---
end
else
if(a111)
--**----
else
--***---
end
end
end
晕死,我自己看得头都晕了,各位大大一般是怎么写的?
本来想用declare @sql nvarchar(1000)
set @sql='....'
exec(@sql)
这样来实现的,但里面有return直接执行SQL语句不行
用exec 存储过程名 参数 这样写又要改存储过程参数,代码也要改,麻烦
请教