求SQL:当条件数据为空时,则查询所有字段的集

发哥 2010-08-20 08:39:02
select * from a

当A中的字段 id is not null时
则查询id条件为 id in(1,2,3,4,5)

应该如何写这条SQL语句?望各位达人给予指导,谢谢。
...全文
511 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
duanzhi1984 2010-08-20
  • 打赏
  • 举报
回复
if exists (select * from a where id is not null)
select * from a where id in (1,2,3,4,5)
王向飞 2010-08-20
  • 打赏
  • 举报
回复
select * from a
where id in (1,2,3,4,5)
union all
select * from a
where id is null
lcqtgb 2010-08-20
  • 打赏
  • 举报
回复
if exists (select * from a where id is not null)
select * from a
where id in (1,2,3,4,5)
lcqtgb 2010-08-20
  • 打赏
  • 举报
回复
select * from a
where id is not null and id in (1,2,3,4,5)

22,209

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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