请教大力、邹等高手!!

mycenter1117 2003-10-17 10:58:25
有三张表table1、table2、table3,如果table1.ID=0那么table1需要join table2,否则table1需要join table3,下面的语句总是提示"在关键字 'case' 附近有语法错误。"不知道为什么?请高手指教,在线等!!

select *
from table1
(case
when table1.ID=0 then ( join table2 on ...)
else ( join table3 on ...)
end)
...全文
31 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
yujohny 2003-10-17
  • 打赏
  • 举报
回复
case不能这样用,必须改为:
select *
from table1 inner join table2 on ……
where table1.ID=0
union all
select *
from table1 inner join table3 on ……
where table1.ID<>0
aierong 2003-10-17
  • 打赏
  • 举报
回复

select *
from table1
join table2 on ...
when table1.ID=0
union all
select *
from table1
join table3 on ...
when table1.ID<>0

22,207

社区成员

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

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