22,206
社区成员
发帖
与我相关
我的任务
分享
Create view vw_test
as
select A.*,isnull(B.val,C.val)
from A
left join B on A.keyid=B.keyid and A.type=10
left join C on A.keyID=c.Keyid and a.type=20
where a.type in(10,20)
-- 楼上整理,不过好像只可以取到B表或者C表的一个字段或者几个字段的值
if object_id(N'v_test') is not null
drop view v_test
go
Create view v_test
as
Select
A.*
, case when a.type = 10 then B表值 else null end as bvalue ,
, case when a.type = 20 then C表值 else null end as cvalue
from a
inner join b on a.id = b.id
inner join c on a.id = c.id