cancel
Showing results for 
Search instead for 
Did you mean: 

Query for Opening Stock + Purchase Qty + Sales Qty

Former Member
0 Kudos

Hi ,

Can anyboday help me by how to develop a query for the following requirement. If any custom query is available please provide me .We are working on SBO 2007B PL 8. The required report structure is

ItemNo ***OpeningStock**** Purchase ********* Sales****

(Batchwise)** Qty*** Value ****Qty** Value ***Qty***Value

Thanks & Regards

Srini

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Srini,

I found this on the forum, see if it helps you;

 select b.Itemcode,b.Item_Description,b.UOM, b.rate as Rate,b.Opening_Stock,b.Receipt,b.Issue, b.Material_Revalue,b.Closing_Stock,b.Closing_Value from (select *,(case closing_stock when 0 then 0 else(Closing_Value/Closing_Stock)end) as Rate from( SELECT T0.Itemcode as 'Itemcode' ,min(T0.Dscription) as 'Item_Description', max(T1.InvntryUom) as UOM, (isnull((Select sum(isnull(inqty,0)) from OINM O1 where O1.itemcode=T1.itemcode and O1.docdate<'[%0]' and O1.transtype in (58,59,20,16,67,-2)),0) - isnull((Select sum(isnull(outqty,0)) from OINM O1 where O1.itemcode=T1.itemcode and O1.docdate<'[%0]' and O1.transtype in (58,21,19,60,15,67,-2,13)),0)+ (isnull((Select sum(isnull(inqty,0)) from OINM O1 where O1.itemcode=T1.itemcode and O1.docdate>='[%0]' and O1.docdate<='[%1]' and O1.transtype in (-2)),0) - isnull((Select sum(isnull(outqty,0)) from OINM O1 where O1.itemcode=T1.itemcode and O1.docdate>='[%0]' and O1.docdate<='[%1]' and O1.transtype in (-2)),0)))as Opening_Stock, (isnull((Select sum(isnull(inqty,0)) from OINM O1 where O1.itemcode=T1.itemcode and O1.docdate>='[%0]' and O1.docdate<='[%1]' and O1.inqty>0 and O1.transtype in (20,18)),0) + isnull((Select sum(isnull(inqty,0)) from OINM O1 where O1.itemcode=T1.itemcode and O1.docdate>='[%0]' and O1.docdate<='[%1]' and O1.inqty>0 and O1.transtype in (67)),0) + isnull((Select sum(isnull(inqty,0)) from OINM O1 where O1.itemcode=T1.itemcode and O1.docdate>='[%0]' and O1.docdate<='[%1]' and O1.inqty>0 and O1.transtype in (58,59,16,14)),0)) as Receipt, (isnull((Select sum(isnull(outqty,0)) from OINM O1 where O1.itemcode=T1.itemcode and O1.docdate>='[%0]' and O1.docdate<='[%1]' and O1.outqty>0 and O1.transtype in (13,15)),0) + isnull((Select sum(isnull(outqty,0)) from OINM O1 where O1.itemcode=T1.itemcode and O1.docdate>='[%0]' and O1.docdate<='[%1]' and O1.outqty>0 and O1.transtype in (67)),0)+ isnull((Select sum(isnull(outqty,0)) from OINM O1 where O1.itemcode=T1.itemcode and O1.docdate>='[%0]' and O1.docdate<='[%1]' and O1.outqty>0 and O1.transtype in (58,60,21,19)),0)) as Issue, isnull((select sum(Transvalue) from OINM O1 where O1.itemcode=T1.itemcode and O1.docdate<='[%1]' and O1.transtype in (162)),0) as Material_Revalue, (isnull((Select sum(isnull(inqty,0)) from OINM O1 where O1.itemcode=T1.itemcode and O1.docdate<='[%1]' and O1.transtype in (58,59,20,16,14,19,67,-2)),0) - isnull((Select sum(isnull(outqty,0)) from OINM O1 where O1.itemcode=T1.itemcode and O1.docdate<='[%1]' and O1.transtype in (58,21,19,60,15,67,-2,13)),0))as Closing_Stock, isnull((select sum(Transvalue) from OINM O1 where O1.itemcode=T1.itemcode and O1.docdate<='[%1]' and O1.transtype in (58,18,-2,67,59,20,16,14,15,13,21,19,60,69,162)),0) as Closing_Value FROM OINM T0 INNER JOIN OITM T1 ON T0.ItemCode = T1.ItemCode INNER JOIN OITW T2 ON T1.ItemCode = T2.ItemCode INNER JOIN OITB B1 ON T1.ItmsGrpCod=B1.ItmsGrpCod where ((B1.ItmsGrpNam>='[%2]' and B1.ItmsGrpNam<='[%3]') or ('[%2]'='' and '[%3]'='')) GROUP BY T1.itemcode,T0.Itemcode )a Where (a.Opening_Stock + a.Receipt + a.Issue + a.Material_Revalue + a.Closing_Stock + a.Closing_Value) <> 0 )b  

Thanks,

Joseph

former_member196081
Active Contributor
0 Kudos

Hi Joseph,

I did try this but its giving a no of errors.

Thanks

Deepak Tyagi

Former Member
0 Kudos

select b.Itemcode,b.Item_Description,b.UOM, b.rate as Rate,b.Opening_Stock,b.Receipt,b.Issue, b.Material_Revalue,b.Closing_Stock,b.Closing_Value from (select *,(case closing_stock when 0 then 0 else(Closing_Value/Closing_Stock)end) as Rate from( SELECT T0.Itemcode as 'Itemcode' ,min(T0.Dscription) as 'Item_Description', max(T1.InvntryUom) as UOM, (isnull((Select sum(isnull(inqty,0)) from OINM O1 where O1.itemcode=T1.itemcode and O1.docdate<'[%0]' and O1.transtype in (58,59,20,16,67,-2)),0) - isnull((Select sum(isnull(outqty,0)) from OINM O1 where O1.itemcode=T1.itemcode and O1.docdate<'[%0]' and O1.transtype in (58,21,19,60,15,67,-2,13)),0)+ (isnull((Select sum(isnull(inqty,0)) from OINM O1 where O1.itemcode=T1.itemcode and O1.docdate>='[%0]' and O1.docdate<='[%1]' and O1.transtype in (-2)),0) - isnull((Select sum(isnull(outqty,0)) from OINM O1 where O1.itemcode=T1.itemcode and O1.docdate>='[%0]' and O1.docdate<='[%1]' and O1.transtype in (-2)),0)))as Opening_Stock, (isnull((Select sum(isnull(inqty,0)) from OINM O1 where O1.itemcode=T1.itemcode and O1.docdate>='[%0]' and O1.docdate<='[%1]' and O1.inqty>0 and O1.transtype in (20,18)),0) + isnull((Select sum(isnull(inqty,0)) from OINM O1 where O1.itemcode=T1.itemcode and O1.docdate>='[%0]' and O1.docdate<='[%1]' and O1.inqty>0 and O1.transtype in (67)),0) + isnull((Select sum(isnull(inqty,0)) from OINM O1 where O1.itemcode=T1.itemcode and O1.docdate>='[%0]' and O1.docdate<='[%1]' and O1.inqty>0 and O1.transtype in (58,59,16,14)),0)) as Receipt, (isnull((Select sum(isnull(outqty,0)) from OINM O1 where O1.itemcode=T1.itemcode and O1.docdate>='[%0]' and O1.docdate<='[%1]' and O1.outqty>0 and O1.transtype in (13,15)),0) + isnull((Select sum(isnull(outqty,0)) from OINM O1 where O1.itemcode=T1.itemcode and O1.docdate>='[%0]' and O1.docdate<='[%1]' and O1.outqty>0 and O1.transtype in (67)),0)+ isnull((Select sum(isnull(outqty,0)) from OINM O1 where O1.itemcode=T1.itemcode and O1.docdate>='[%0]' and O1.docdate<='[%1]' and O1.outqty>0 and O1.transtype in (58,60,21,19)),0)) as Issue, isnull((select sum(Transvalue) from OINM O1 where O1.itemcode=T1.itemcode and O1.docdate<='[%1]' and O1.transtype in (162)),0) as Material_Revalue, (isnull((Select sum(isnull(inqty,0)) from OINM O1 where O1.itemcode=T1.itemcode and O1.docdate<='[%1]' and O1.transtype in (58,59,20,16,14,19,67,-2)),0) - isnull((Select sum(isnull(outqty,0)) from OINM O1 where O1.itemcode=T1.itemcode and O1.docdate<='[%1]' and O1.transtype in (58,21,19,60,15,67,-2,13)),0))as Closing_Stock, isnull((select sum(Transvalue) from OINM O1 where O1.itemcode=T1.itemcode and O1.docdate<='[%1]' and O1.transtype in (58,18,-2,67,59,20,16,14,15,13,21,19,60,69,162)),0) as Closing_Value FROM OINM T0 INNER JOIN OITM T1 ON T0.ItemCode = T1.ItemCode INNER JOIN OITW T2 ON T1.ItemCode = T2.ItemCode INNER JOIN OITB B1 ON T1.ItmsGrpCod=B1.ItmsGrpCod where ((B1.ItmsGrpNam>='[%2]' and B1.ItmsGrpNam<='[%3]') or ('[%2]'='' and '[%3]'='')) GROUP BY T1.itemcode,T0.Itemcode )a Where (a.Opening_Stock + a.Receipt + a.Issue + a.Material_Revalue + a.Closing_Stock + a.Closing_Value) <> 0 )b

Try this one.

Thanks,

Joseph

Edited by: Joseph Antony on Jul 7, 2010 1:03 PM

Former Member
0 Kudos

Dear Joseph,

when i use this its giving this "ERROR".

1). [Microsoft][SQL Native Client][SQL Server]Incorrect syntax near ' and O1.transtype in 'Service Contracts' (OCTR) (58,21,19,60,15,67,-2,13)),0)+ (isnull((Select sum(isnull(inqty,0)) from OINM O1 where O1.itemcode=T1.itemc'.

plz help ..

Thanks,

Jrajput.

former_member196081
Active Contributor
0 Kudos

Hi Try Below Code..


select b.Itemcode,b.Item_Description,b.UOM, b.rate as Rate,b.Opening_Stock,b.Receipt,b.Issue, b.Material_Revalue,b.Closing_Stock,b.Closing_Value from (select *,(case closing_stock when 0 then 0 else(Closing_Value/Closing_Stock)end) as Rate from( SELECT T0.Itemcode as 'Itemcode' ,min(T0.Dscription) as 'Item_Description', max(T1.InvntryUom) as UOM, (isnull((Select sum(isnull(inqty,0)) from OINM O1 where O1.itemcode=T1.itemcode and O1.docdate<'' and O1.transtype in (58,59,20,16,67,-2)),0) - isnull((Select sum(isnull(outqty,0)) from OINM O1 where O1.itemcode=T1.itemcode and O1.docdate<[%0] and O1.transtype in (58,21,19,60,15,67,-2,13)),0)+ (isnull((Select sum(isnull(inqty,0)) from OINM O1 where O1.itemcode=T1.itemcode and O1.docdate>=[%0] and O1.docdate<=[%1] and O1.transtype in (-2)),0) - isnull((Select sum(isnull(outqty,0)) from OINM O1 where O1.itemcode=T1.itemcode and O1.docdate>=[%0] and O1.docdate<=[%1] and O1.transtype in (-2)),0)))as Opening_Stock, (isnull((Select sum(isnull(inqty,0)) from OINM O1 where O1.itemcode=T1.itemcode and O1.docdate>=[%0] and O1.docdate<=[%1] and O1.inqty>0 and O1.transtype in (20,18)),0) + isnull((Select sum(isnull(inqty,0)) from OINM O1 where O1.itemcode=T1.itemcode and O1.docdate>=[%0] and O1.docdate<=[%1] and O1.inqty>0 and O1.transtype in (67)),0) + isnull((Select sum(isnull(inqty,0)) from OINM O1 where O1.itemcode=T1.itemcode and O1.docdate>=[%0] and O1.docdate<=[%1] and O1.inqty>0 and O1.transtype in (58,59,16,14)),0)) as Receipt, (isnull((Select sum(isnull(outqty,0)) from OINM O1 where O1.itemcode=T1.itemcode and O1.docdate>=[%0] and O1.docdate<=[%1] and O1.outqty>0 and O1.transtype in (13,15)),0) + isnull((Select sum(isnull(outqty,0)) from OINM O1 where O1.itemcode=T1.itemcode and O1.docdate>=[%0] and O1.docdate<=[%1] and O1.outqty>0 and O1.transtype in (67)),0)+ isnull((Select sum(isnull(outqty,0)) from OINM O1 where O1.itemcode=T1.itemcode and O1.docdate>=[%0] and O1.docdate<=[%1] and O1.outqty>0 and O1.transtype in (58,60,21,19)),0)) as Issue, isnull((select sum(Transvalue) from OINM O1 where O1.itemcode=T1.itemcode and O1.docdate<=[%1] and O1.transtype in (162)),0) as Material_Revalue, (isnull((Select sum(isnull(inqty,0)) from OINM O1 where O1.itemcode=T1.itemcode and O1.docdate<=[%1] and O1.transtype in (58,59,20,16,14,19,67,-2)),0) - isnull((Select sum(isnull(outqty,0)) from OINM O1 where O1.itemcode=T1.itemcode and O1.docdate<=[%1] and O1.transtype in (58,21,19,60,15,67,-2,13)),0))as Closing_Stock, isnull((select sum(Transvalue) from OINM O1 where O1.itemcode=T1.itemcode and O1.docdate<=[%1] and O1.transtype in (58,18,-2,67,59,20,16,14,15,13,21,19,60,69,162)),0) as Closing_Value FROM OINM T0 INNER JOIN OITM T1 ON T0.ItemCode = T1.ItemCode INNER JOIN OITW T2 ON T1.ItemCode = T2.ItemCode INNER JOIN OITB B1 ON T1.ItmsGrpCod=B1.ItmsGrpCod where ((B1.ItmsGrpNam>=[%2] and B1.ItmsGrpNam<=[%3]) ) GROUP BY T1.itemcode,T0.Itemcode )a Where (a.Opening_Stock + a.Receipt + a.Issue + a.Material_Revalue + a.Closing_Stock + a.Closing_Value) <> 0 )b

Deepak Tyagi

Answers (0)