A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
Hi @Analyst_SQL ,
Please refer below:
;with B as (
select a.Descriptionitem,sum(b.Bweight) Bweight,b.Entrydate, FName ,c.FID
from #ItemMasterFile a
inner join #Bigbalprd b on a.Codeitem=b.Codeitem
inner join #floor c on c.FID=b.FID
group by a.Descriptionitem,b.Entrydate,c.FName,c.FID)
,C as (
select a.FID,sum(a.iWeight) iWeight,EntryDate
from #ConIssuance a
inner join #floor b on b.FID=a.FID
group by a.FID,EntryDate)
select b.Entrydate [Date],upper(b.Descriptionitem) Description,B.Bweight,C.iWeight
, cast(B.Bweight as float)/cast(C.iWeight as float)*100 [Percentage], B.FName [Floor]
from B
inner join C on B.FID=C.FID
Output:
Date Description Bweight iWeight Percentage Floor
2021-04-01 A 700 1600 43.75 First
2021-04-01 A 300 2800 10.7142857142857 Second
2021-04-01 F 400 2800 14.2857142857143 Second
Best regards,
Melissa
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.