开发者

How to check for empty table and terminate stored procedure

If table is not empty then show content of the table and does not execute rest of script. How to achive this? What is the best methodology? set noexec on, or raiserror? or use Re开发者_如何转开发turn?

Thanks!


if exists(select top 1 NULL from <your_table_name>)
begin
  --do something if you need

  select col1, col2,... from <your_table_name>
  where <your_condition>

  --do other things if needed
end
else
  return   <-- this will stop right here and return


It depends on what the usage of the stored procedure is in context but RETURN is the simplest and most straightforward solution.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜