Dear Nagarajan
See below:
# | Warehouse | Item No. | Item Desc | Price in CZK | Opening Balance | IN | OUT | Closing |
1 | WH1 | 0 | 0 | 0 | 0 | 0 | ||
2 | WH1 | 3S | Pxxxxxx | 104.9108 | 0 | 0 | 0 | 0 |
3 | WH1 | 3S 2 | Pxxxxxx2 | 99.8322 | 0 | 0 | 0 | 0 |
4 | WH1 | COMP1000 | Pxxxxxx3 | 0.221 | 0 | 0 | 0 | 0 |
For the UoM form OITM, i can't seem to grasp the logic, when i just add your text, it is not working...
Now regarding the Item Group, i have managed to change the code as follow, no issue. But for the warehouse since i want the warehouse to appear in first column i do not know how to do:
Declare @Whse nvarchar(10) |
Declare @FromDate DateTime |
Declare @ToDate DateTime |
Declare @Group1 nvarchar(10) |
Declare @Group2 nvarchar(10) |
Set @FromDate = (Select min(S0.Docdate) from dbo.OINM S0 where S0.Docdate >='[%0]') |
Set @ToDate = (Select max(S1.Docdate) from dbo.OINM s1 where S1.Docdate <='[%1]') |
Set @Group1 = (Select min(s2.ItmsGrpCod) from dbo.OITB S2 Where S2.ItmsGrpNam = '[%2]' ) |
Set @Group2 = (Select max(s3.ItmsGrpCod) from dbo.OITB S3 Where S3.ItmsGrpNam = '[%3]') |
Set @Whse = (Select max(s4.Warehouse) from dbo.OINM S4 Where S4.Warehouse = '[%4]') |
Select @Whse as 'Warehouse', a.Itemcode, max(a.Dscription) as 'Item Desc',max(a.Price) as 'Price in CZK', sum(a.[Opening Balance]) as [Opening Balance], sum(a.[IN]) as [IN], sum(a.OUT) as OUT, ((sum(a.[Opening Balance]) + sum(a.[IN])) - Sum(a.OUT)) as Closing from dbo.OITM I1 Left JOIN (Select N1.Warehouse, N1.Itemcode, N1.Dscription,N1.Price, (sum(N1.inqty)-sum(n1.outqty)) as [Opening Balance], 0 as [IN], 0 as OUT |
From dbo.OINM N1 |
Where N1.DocDate < @FromDate and N1.Warehouse = @Whse |
Group By N1.Warehouse,N1.ItemCode,N1.Dscription,N1.Price |
Union All |
select N1.Warehouse, N1.Itemcode, N1.Dscription,N1.price, 0 as [Opening Balance], sum(N1.inqty) as [IN], 0 as OUT |
From dbo.OINM N1 |
Where N1.DocDate >= @FromDate and N1.DocDate <= @ToDate and N1.Inqty >0 and N1.Warehouse = @Whse |
Group By N1.Warehouse,N1.ItemCode,N1.Dscription,N1.price |
Union All |
select N1.Warehouse, N1.Itemcode, N1.Dscription,N1.price, 0 as [Opening Balance], 0 as [IN], sum(N1.outqty) as OUT |
From dbo.OINM N1 |
Where N1.DocDate >= @FromDate and N1.DocDate <=@ToDate and N1.OutQty > 0 and N1.Warehouse = @Whse |
Group By N1.Warehouse,N1.ItemCode,N1.Dscription,N1.price) a ON a.ItemCode=I1.ItemCode |
where I1.ItmsGrpCod >= @Group1 and I1.ItmsGrpCod <= @Group2 |
Group By a.Itemcode |
Order By a.Itemcode |