This SQL query retrieves transfer order information from various tables in a database for items categorized as production spares, spares, or products. It first identifies distinct transfer orders from item ledger entries. It then selects item details, product information, transfer details, costs, and other fields from various tables, filtering for transfer order numbers from the initial subquery and locations not containing "INTST". The results are filtered to only include item groups that are null or in the specified categories.
This SQL query retrieves transfer order information from various tables in a database for items categorized as production spares, spares, or products. It first identifies distinct transfer orders from item ledger entries. It then selects item details, product information, transfer details, costs, and other fields from various tables, filtering for transfer order numbers from the initial subquery and locations not containing "INTST". The results are filtered to only include item groups that are null or in the specified categories.
This SQL query retrieves transfer order information from various tables in a database for items categorized as production spares, spares, or products. It first identifies distinct transfer orders from item ledger entries. It then selects item details, product information, transfer details, costs, and other fields from various tables, filtering for transfer order numbers from the initial subquery and locations not containing "INTST". The results are filtered to only include item groups that are null or in the specified categories.
from [dbo].[SEVEN-UP - IKEJA$Item Ledger Entry] i inner join [dbo].[SEVEN-UP - IKEJA$Item] it with (nolock, readuncommitted) on it. [No_] = i.[Item No_] LEFT JOIN [dbo].[SEVEN-UP - IKEJA$Product Group] as ProdGroup on it.[Product Group Code] = ProdGroup.Code left join [dbo].[SEVEN-UP - IKEJA$Transfer Shipment Header] tsh with (nolock, readuncommitted) on tsh.[Transfer Order No_] = i.[Transfer Order No_] LEFT JOIN (SELECT [Item Ledger Entry No_], [Product Group Code], sum([Cost per Unit]) [Cost per Unit], sum([Cost Posted to G_L]) [Cost Posted to G_L] FROM [dbo].[SEVEN-UP - IKEJA$Value Entry] with (nolock, readuncommitted) group by [Item Ledger Entry No_],[Product Group Code]) ve ON ve.[Item Ledger Entry No_] = i.[Entry No_] AND i.[Entry No_] = ve.[Item Ledger Entry No_] where i.[Location Code] NOT LIKE '%INTST%' AND i.[Document No_] like '%TRRP%' ---and i.[Global Dimension 1 Code] = '001' ), LSRTransfers as ( SELECT --count(*) ---@Region, i.[Item No_] ,i.[Description] ,i.[Item Category Code] ,it.[Product Identification Code] ,it.[Gen_ Prod_ Posting Group] ,it.[Container Identification Code] ----,i.[Global Dimension 1 Code] as [Region Centre] ,i.[Global Dimension 3 Code] as [Cost Centre] ,i.[Transfer - Budget Center] ,i.[Prod_ Order No_] ,tsh.[Store-to] ,tsh.[Transfer-to Code] , case when ProdGroup.Description like '%RAW%' then 'RAW MATERIALS' WHEN it.[Item Category Code] = 'PRODUCTS' then 'PRODUCTS' WHEN ProdGroup.[Description] = 'PRODUCTION SPARES' then 'PRODUCTION SPARES' when it.[Item Category Code] = 'SPARES' THEN 'SPARES' ELSE ProdGroup.Description END AS [Item Group], i.[Unit of Measure Code], i. [Location Code],i.[Transaction Dimension 5 Code], i.[Document No_], i.[External Document No_], i.[Transfer Order No_] , CONVERT(VARCHAR(10), i.[Posting Date], 120) AS "Posting Date" , ( select top 1 gl.[User ID] from [dbo].[SEVEN-UP - IKEJA$G_L Entry] gl with (nolock, readuncommitted) where i.[Document No_] = gl.[Document No_] and gl.[User ID] is not null and gl.[User ID] != '' ORDER BY gl.[timestamp] ASC) as [User ID],i.[Entry Type] , CASE WHEN i.[Unit of Measure Code] = 'BOTTLE' THEN i.Quantity/24 ELSE i.Quantity END AS Quantity --, i.* , CASE WHEN i.[Unit of Measure Code] = 'BOTTLE' THEN i.[Invoiced Quantity]/24 ELSE i.[Invoiced Quantity] END AS [Invoiced Quantity] ,ve.[Cost per Unit] ,ve.[Cost Posted to G_L] from [dbo].[SEVEN-UP - IKEJA$Item Ledger Entry] i with (nolock, readuncommitted) inner join [dbo].[SEVEN-UP - IKEJA$Item] it with (nolock, readuncommitted) on it. [No_] = i.[Item No_] LEFT JOIN [dbo].[SEVEN-UP - IKEJA$Product Group] as ProdGroup on it.[Product Group Code] = ProdGroup.Code left join [dbo].[SEVEN-UP - IKEJA$Transfer Shipment Header] tsh with (nolock, readuncommitted) on tsh.[Transfer Order No_] = i.[Transfer Order No_] LEFT JOIN (SELECT [Item Ledger Entry No_], [Product Group Code], sum([Cost per Unit]) [Cost per Unit], sum([Cost Posted to G_L]) [Cost Posted to G_L] FROM [dbo].[SEVEN-UP - IKEJA$Value Entry] with (nolock, readuncommitted) group by [Item Ledger Entry No_],[Product Group Code]) ve ON ve.[Item Ledger Entry No_] = i.[Entry No_] AND i.[Entry No_] = ve.[Item Ledger Entry No_] where i.[Transfer Order No_] in (Select aux.[Transfer Order No_] from ReceivedTransfers aux) and i.[Location Code] NOT LIKE '%INTST%' AND i.[External Document No_] = '' and i.[Document No_] like '%TRRP%')
select * from LSRTransfers
where [Item Group] is null or [Item Group] in ('PRODUCTION SPARES','SPARES','PRODUCTS')
-----002-MFT21-2200186 --SELECT * --from [dbo].[SEVEN-UP - IKEJA$Item Ledger Entry] i with (nolock, readuncommitted) --WHERE [Item No_] = 'FMB001'