我有一个存储过程,我将整数参数传递给(@truncate
)。
我想要的就是这个。
if @truncate = 1
then
truncate some_table
do something else
else
do only the "do something else" (before the else) without truncating the table..
代码中的“执行其他操作”部分很长。如何在不重复“执行其他操作”代码的情况下执行此操作并使存储过程超出必要的时间?
答案 0 :(得分:4)
如果我理解正确,你只需要IF
来覆盖截断,而其他逻辑应该总是执行。因此,只需删除ELSE
条件,并将该逻辑放在IF
。
if @truncate = 1
begin
truncate some_table
end
do something else -- always do this