Lot of SQL Programmer is facing the issue many Times-
When they have to add all columns value in last
I searched a lot to get the solution of this regarding to issue
count(prod_booking_heat_no) as [Total Heat Per Day],
sum([Production Qty]) as [Metal Production Per DAY]
from(
select a.sr_no,convert(varchar,a.Prod_Date,103) as [Production Date],
a.prod_booking_heat_no,
c.IT_NAME ,
A.prod_booking_item_no AS [Product Name],
A.prod_booking_laddle_no as [Laddle No],avg(b.alt_qty) [Production Qty],
from Direct_Prod_Mast a
left outer join Prod_Output_Det b on a.urn_no=b.urn_no
left outer join ItemMaster c on c.IT_CODE=b.IT_CODE
left outer join Prod_Input_Det d on d.urn_no=b.urn_no
left outer join ItemMaster e on e.IT_CODE=d.IT_CODE
where c.IT_NAME like '%Metal%' and a.co_code='GEN00A000001' and a.Prod_Date>=@fromdate and a.Prod_Date<=@todate
group by a.Prod_Date,a.Sr_No,a.prod_booking_heat_no,c.IT_NAME,A.prod_booking_item_no,A.prod_booking_laddle_no
) as b11
When they have to add all columns value in last
I searched a lot to get the solution of this regarding to issue
Hear is the query-
Logic IS- I convert everything in Archaic format-
select convert(varchar,[Production Date]) as [Production Date],count(prod_booking_heat_no) as [Total Heat Per Day],
sum([Production Qty]) as [Metal Production Per DAY]
from(
select a.sr_no,convert(varchar,a.Prod_Date,103) as [Production Date],
a.prod_booking_heat_no,
c.IT_NAME ,
A.prod_booking_item_no AS [Product Name],
A.prod_booking_laddle_no as [Laddle No],avg(b.alt_qty) [Production Qty],
from Direct_Prod_Mast a
left outer join Prod_Output_Det b on a.urn_no=b.urn_no
left outer join ItemMaster c on c.IT_CODE=b.IT_CODE
left outer join Prod_Input_Det d on d.urn_no=b.urn_no
left outer join ItemMaster e on e.IT_CODE=d.IT_CODE
where c.IT_NAME like '%Metal%' and a.co_code='GEN00A000001' and a.Prod_Date>=@fromdate and a.Prod_Date<=@todate
group by a.Prod_Date,a.Sr_No,a.prod_booking_heat_no,c.IT_NAME,A.prod_booking_item_no,A.prod_booking_laddle_no
) as b11
No comments:
Post a Comment