Quantcast
Channel: SCN : All Content - All Communities
Viewing all articles
Browse latest Browse all 3280

Pivot Query by the Qty in Warehouse

$
0
0

Hi,


I have the following query that works fine.


SELECT     T0.ItemCodeAS'Item Code',t2.ItemNameAS'Item Name',T3.ItmsGrpNamAS'Item Group',t4.CardCodeAS'Default Supplier',t4.CardNameAS'Supplier Name',

t5.GroupNameAS'Group Code',SUM(T0.InQty-T0.OutQty)AS'Inventory Qty',SUM(T0.TransValue)AS'Inventory Value'

FROM         dbo.OINMAST0INNERJOIN

dbo.OITMASt2ONt2.ItemCode=T0.ItemCodeLEFTOUTERJOIN

dbo.OITBAST3ONT3.ItmsGrpCod=t2.ItmsGrpCodLEFTOUTERJOIN

dbo.OCRDASt4ONt4.CardCode=t2.CardCodeLEFTOUTERJOIN

dbo.OCRGASt5ONt5.GroupCode=t4.GroupCode

WHERE (T0.DocDate <= [%0] ) and T0.ItemCode='XXX'

GROUPBYT0.ItemCode,T3.ItmsGrpNam,t2.ItemName,t4.CardCode,t4.CardName,t5.GroupName,LEFT(T0.ItemCode, 2)

HAVING (SUM(T0.InQty-T0.OutQty)> 0)



However, I want to pivot it with the sum of the Inventory Qty by the warehouse it is in to display in the columns at the end of the results but I'm stuck up to the below point.  I also want to have the Inventory Value by warehouse beside the qty by warehouse it is displayed by but will settle for the quantity for now.  Can anybody spot where this is going wrong?


SELECT  

ISNULL(1,0)as[01],

ISNULL(2,0)as[02],

ISNULL(3,0)as[03]

FROM (SelectT0.ItemCodeAS'Item Code',t2.ItemNameAS'Item Name',T3.ItmsGrpNamAS'Item Group',t4.CardCodeAS'Default Supplier',t4.CardNameAS'Supplier Name',

t5.GroupNameAS'Group Code',SUM(T0.InQty-T0.OutQty)AS'Inventory Qty',SUM(T0.TransValue)AS'Inventory Value',T0.Warehouseas'Warehouse'

 

fromdbo.OINMAST0INNERJOIN

dbo.OITMASt2ONt2.ItemCode=T0.ItemCodeLEFTOUTERJOIN

dbo.OITBAST3ONT3.ItmsGrpCod=t2.ItmsGrpCodLEFTOUTERJOIN

dbo.OCRDASt4ONt4.CardCode=t2.CardCodeLEFTOUTERJOIN

dbo.OCRGASt5ONt5.GroupCode=t4.GroupCode

WHERE (T0.DocDate <= [%0] ) andT0.ItemCode='XXX')S

PIVOT

(SUM(InventoryQty)

For[Warehouse]IN(01, 02, 03)

)P

 

GROUPBYT0.ItemCode,T3.ItmsGrpNam,t2.ItemName,t4.CardCode,t4.CardName,t5.GroupName,LEFT(T0.ItemCode, 2),T0.Warehouse

HAVING      (SUM(T0.InQty-T0.OutQty)> 0)


Thanks


Viewing all articles
Browse latest Browse all 3280

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>