开发者

How to check for empty table and terminate stored procedure

开发者 https://www.devze.com 2023-03-13 18:54 出处:网络
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?

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

精彩评论

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