At this moment I have a table tblLocation
with columns ID, Location, PartOfID
.
The table is recursively connected to itself: PartOfID -> ID
My goal is to have a select output as followed:
> France > Paris > AnyCity >
Explanation: AnyCity is located in Paris, Paris is located in France.
My solution that I found until now was this:
; with q as (
select ID,Location,PartOf_LOC_id from tblLocatie t
where t.ID = 1 -- 1 represents an example
union all
select t.Location + '>' from tblLocation t
inner join q parent on parent.ID = t.LOC_PartOf_ID
)
select * from q
Unfortunately I get the following error:
All queries combined using a UNION, INTERSECT or EXCEPT operator must have an equal number of expressions in their target lists.
If you have any idea how I could fix my output it would be great.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…