[PropertyId]에 대한 추가 조인 정보를 추가 할 때 이것이 왜 0 레코드를 반환하는지 설명 할 수 있습니까? 나는 이것이 단순한 것이지만, 나는 손실을 입었다 고 알고있다. 당신이 가입하지 추가 한 경우CTE가 추가 조인 절이 작동하지 않습니다.
declare @ViewId as int;
set @ViewId = 11;
with Views
as
(
select [LiveWireView].[Id], [LiveWireView].[Name], [LiveWireView].[ParentId], [PropertyToViewMap].[PropertyId]
from [LiveWireView]
inner join [PropertyToViewMap] on [PropertyToViewMap].[ViewId] = [LiveWireView].[Id]
where [LiveWireView].[Id] = @ViewId
union all
select [v].[Id], [v].[Name], [v].[ParentId], [p].[PropertyId]
from [LiveWireView] v
inner join [PropertyToViewMap] p on [p].[ViewId] = [v].[Id]
inner join Views on Views.Id = v.ParentId
)
select [PropertyId] from Views;
[Sql Fiddle] (http://sqlfiddle.com/)에서 샘플을 만드시겠습니까? –
결과가 표시됩니까? SELECT * FROM PropertyToViewMap WHERE ViewId = 11 – GilM