Created
March 6, 2019 17:27
-
-
Save TaylanUB/204050a6deb25625de7cea88af4b1bd7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select r.DocEntry as rdrDocId, | |
r1.LineNum as rdrLineId | |
into #orderLines | |
from rdr1 r1 | |
join ordr r on r.DocEntry = r1.DocEntry | |
-- If I filter only by LineStatus or only by DocStatus here, query takes <1s | |
where r1.LineStatus = 'O' and r.DocStatus = 'O' | |
select U_KommNr as pklDocId, | |
max(cast(U_Space as int)) as maxPlace | |
into #picklistDetails | |
from [@PICKING] | |
where U_DeletedF = 'N' | |
group by U_KommNr | |
select p.AbsEntry as pklDocId, | |
-- If I remove the following reference to pd, query takes <1s | |
case | |
when pd.maxPlace is null then 0 | |
else pd.maxPlace | |
end as pklDocMaxPlace | |
into #picklistDocs | |
from opkl p | |
left join #picklistDetails pd on pd.pklDocId = p.AbsEntry | |
select AbsEntry as pklDocId, | |
PickEntry as pklLineId, | |
OrderEntry as rdrDocId, | |
OrderLine as rdrLineId | |
into #picklistDocLines | |
from PKL1 | |
select p.pklDocMaxPlace | |
from #picklistDocs p | |
join #picklistDocLines p1 on p.pklDocId = p1.pklDocId | |
join #orderLines r1 on r1.rdrDocId = p1.rdrDocId | |
and r1.rdrLineId = p1.rdrLineId | |
drop table #picklistDocs, #picklistDocLines, #picklistDetails, #orderLines |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment