cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
CPalaloga
Frequent Visitor

SQL Table view Left Join itself

Hello All,

 

I have a SQL Table view which contain the ID, Start Date, Complete Date and Order.

In Order is written the ID of the parent of this entry. If the parent year is different than 2049 then allow the child entry to start.

 

I want to display to users only the entries that can be done.

I created a Gallery, added the view as source and started filtering it (I use a dipswitch to swap from all to the To Do list), but it doesn't work what I tried since "Start" doesn't record anything:

 

 

Filter( AddColumns( MaCStoCSVe
,"Start"
,LookUp( Filter( MaCStoCSVe
,Year(CompletionDate)<>2049
)
,CSID=MaCStoCSVe[@CSOrder]
).CSID
)
,If( SNWCompleted.Value
,CompletionDate=CompletionDate
,Year(CompletionDate)=2049
)
)

This is how the query looks like in MSSMS:

 

declare @ALL bit = 0

select *
from vw_MDBMaCStoCSVe as dt1
left join (select CSID
from vw_MDBMaCStoCSVe as dt1
where SN = 308550
and dt1.TestCatID = 1
and Year(CompletionDate)<>2049)dt2 on DT2.CSID = DT1.CSOrder
where dt1.SN = 308550
and dt1.TestCatID = 1
and (@All=1
Or (@All=0
and (Year(dt1.CompletionDate)=2049)
and (dt2.CSID is not null
Or dt1.CSID = dt1.CSOrder)
))

 

Does anyone have a suggestion to make a left join of itself?

0 REPLIES 0

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Top Solution Authors
Top Kudoed Authors
Users online (2,908)