SQL QUERY FOR - Item Purchase Tracking
select
a.Pur_Order_No as [Purchase Order No],
convert(varchar,a.Pur_Order_Date,103) as [Purchase Order Date],
c.AC_NAME as [Supplier Name],
b.ALT_QTY as [PO QTY],
b.ALT_RATE as [PO Rate]
from Purchase_Order_mast a
left outer join Purchase_Order_Det b on a.urn_no=b.URN_No
left outer join ACCT_MAST c on a.Supp_Code=c.SR_NO
where IT_CODE=@it_code and
a.Pur_Order_Date>=@fromdate and
a.Pur_Order_Date<=@todate and
a.PO_Status='Approved'
order by a.Pur_Order_Date
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
Hear is the query-
Logic IS- I convert everything in Archaic format-
selectconvert(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