写一个存储过程,如何判断一个select语句的查询结果为空

seagull2008 2005-01-22 11:25:39
如何判断一个select语句的查询结果为空,用if语句怎样写?
...全文
286 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
xluzhong 2005-01-22
  • 打赏
  • 举报
回复
if exists(select count(*) from tablename where 条件)

或用:

select * from tablename where 条件
if @@rowcount>0
print '查询结果不为空'
else
print '查询结果为空'
jess22 2005-01-22
  • 打赏
  • 举报
回复
if exists(select * from 表名 where 条件)
chinaandys 2005-01-22
  • 打赏
  • 举报
回复
if exists(select count(*) from tablename where 条件)

或用:

select * from tablename where 条件
if @@rowcount>0
print '查询结果不为空'
else
print '查询结果为空'
huohw 2005-01-22
  • 打赏
  • 举报
回复
if not exists (select * from 表 where 条件)
isnull(select * from 表 where 条件)
daijingjie2002 2005-01-22
  • 打赏
  • 举报
回复
if (select 字段 from 表 where 字段='返回不大于1的之') is null
begin
end

Qihua_wu 2005-01-22
  • 打赏
  • 举报
回复
if exists(select count(*) from tablename where condition)
daijingjie2002 2005-01-22
  • 打赏
  • 举报
回复
if (select 字段 from 表) is null
begin
end
当然以上返回值必须一个
Softlee81307 2005-01-22
  • 打赏
  • 举报
回复
if not exists(select * from 表 )
print '表是空'
else
print '表不是空'
eddycjh 2005-01-22
  • 打赏
  • 举报
回复
if exists(select count(*) from tablename where 条件)
就可以了

34,593

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧