Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

 SQL Server Forums Profile | Active Topics | Members | Search | Forum FAQ Register Now and get your question answered!
 Username: Password: Save Password Forgot your Password?
 All Forums  Development Tools  Other Development Tools  inventory/stock valuation Reply to Topic  Printer Friendly
Author  Topic

folumike
Starting Member

24 Posts

 Posted - 05/20/2012 :  15:24:30 I am developing an application with vb6 and mssql 2000. I need to get inventory/stock valuation. In the process, i need to calculate using array: Date,Inv#,Qty for val, Cost Price. Then get the average price. See below:Declare i,jk,mk = 0i=1Do while k<=TotQty ie TotQty = total quantityk = k + Qty(i)if k < TotQty or k = TotQty Thenj = [Qty(i) * CostPrice(i) + jelsek > TotQtym = TotQty - (k - Qty(i))j =[[m * costprice(i)] + jend ifwendAvgPrice j/TotQtyPlease help me out. You can give a sample code in whichever way.Thanks

visakh16
Very Important crosS Applying yaK Herder

India
52326 Posts

 Posted - 05/20/2012 :  15:40:11 are you looking for t-sql or vb code?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/

folumike
Starting Member

24 Posts

 Posted - 05/20/2012 :  18:07:54 Any onequote:Originally posted by visakh16are you looking for t-sql or vb code?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/

visakh16
Very Important crosS Applying yaK Herder

India
52326 Posts

 Posted - 05/20/2012 :  19:30:31 hmm...your posted code is a bit confusing. i cant see whats initial value of j. also whats AvgPrice j/TotQty?it would be better if you can post some sample data and explain what you want as output------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/

folumike
Starting Member

24 Posts

 Posted - 05/21/2012 :  17:08:47 TotQty = Balance as at dateSee table belowDate | QtyForValuation | APInv# | CostPrice------------------------------------------------------------BegBalDate | BegBal(QtySupplied) | 'BegBal' | BegPrice | J1APDate(1) | QtyReceived - QtySup | Inv# | ItemPrice | . . | . | . | . | . . | . | . | . | .APDate(n) | n | n | n | JnDeclare i, j , k, mk = 0i = 1i=1Do while k<=TotQty ie TotQty = total quantityk = k + Qty(i)if k < TotQty or k = TotQty Thenj = [Qty(i) * CostPrice(i) + jelsek > TotQtym = TotQty - (k - Qty(i))j =[[m * costprice(i)] + jend ifwendAvgPrice = j/TotQtyNOTEI want to do the valuation and then get the Average price (AvgPrice) as at the selected date.Which is the array vakue divided by TotQtyAvgPrice = j/TotQtyTotQty = Balance as at dateJ is the value for the arrayquote:Originally posteod by visakh16hmm...your posted code is a bit confusing. i cant see whats initial value of j. also whats AvgPrice j/TotQty?it would be better if you can post some sample data and explain what you want as output------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/

folumike
Starting Member

24 Posts

 Posted - 05/21/2012 :  17:30:22 from the table below, Initial values of J are the Begining balances such as opening stock date (BegBal Date), Opeining stock, Price for the opening stock(cost pricequote:Originally posted by folumikeTotQty = Balance as at dateSee table belowDate | QtyForValuation | APInv# | CostPrice------------------------------------------------------------12/jun/2011| 30 | 'BegBal' | 70.00 | J1APDate(1) | 28 | Inv# | 75.00 | . . | . | . | . | . . | . | . | . | .APDate(n) | n | n | n | JnJ is an array to find stock valuation price as at the selected date.Output is Average Price = Jn divided by current stock balancee.g. AvgPrice = Jn/TotQtyfor example; AvgPrice = Jn/45Declare i, j , k, mk = 0i = 1i=1Do while k<=TotQty ie TotQty = total quantityk = k + Qty(i)if k < TotQty or k = TotQty Thenj = [Qty(i) * CostPrice(i) + jelsek > TotQtym = TotQty - (k - Qty(i))j =[[m * costprice(i)] + jend ifwendAvgPrice = j/TotQtyNOTEI want to do the valuation and then get the Average price (AvgPrice) as at the selected date.Which is the array vakue divided by TotQtyAvgPrice = j/TotQtyTotQty = Balance as at dateJ is the value for the arrayquote:Originally posteod by visakh16hmm...your posted code is a bit confusing. i cant see whats initial value of j. also whats AvgPrice j/TotQty?it would be better if you can post some sample data and explain what you want as output------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/

folumike
Starting Member

24 Posts

 Posted - 05/21/2012 :  18:05:48 I dont know how to explain further since I cant sent graphics. Or can you give me a sample code on how to calculate inventory valuation price and how to calculate its average price[quote]Originally posted by folumikefrom the table below, Initial values of J are the Begining balances such as opening stock date (BegBal Date), Opeining stock, Price for the opening stock(cost price[quote]Originally posted by folumikeTotQty = Balance as at dateSee table belowDate | QtyForValuation | APInv# | CostPrice------------------------------------------------------------12/jun/2011| 30 | 'BegBal' | 70.00 | J1APDate(1) | 28 | Inv# | 75.00 | . . | . |

visakh16
Very Important crosS Applying yaK Herder

India
52326 Posts

 Posted - 05/21/2012 :  18:42:04 See how to post proper data for questionhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
Topic
 Reply to Topic  Printer Friendly Jump To: Select Forum General SQL Server Forums       New to SQL Server Programming       New to SQL Server Administration       Script Library       Data Corruption Issues       Database Design and Application Architecture SQL Server 2012 Forums       Transact-SQL (2012)       SQL Server Administration (2012)       SSIS and Import/Export (2012)       Analysis Server and Reporting Services (2012)       Replication (2012)       Availability Groups and DR (2012)       Other SQL Server 2012 Topics SQL Server 2008 Forums       Transact-SQL (2008)       SQL Server Administration (2008)       SSIS and Import/Export (2008)       High Availability (2008)       Replication (2008)       Analysis Server and Reporting Services (2008)       Other SQL Server 2008 Topics SQL Server 2005 Forums       Transact-SQL (2005)       SQL Server Administration (2005)       .NET Inside SQL Server (2005)       SSIS and Import/Export (2005)       Service Broker (2005)       Replication (2005)       High Availability (2005)       Analysis Server and Reporting Services (2005)       Express Edition and Compact Edition (2005)       Other SQL Server Topics (2005) SQL Server 2000 Forums       SQL Server Development (2000)       SQL Server Administration (2000)       Import/Export (DTS) and Replication (2000)       Transact-SQL (2000)       Analysis Services (2000)       MSDE (2000) Development Tools       ASP.NET       Reporting Services Development       Other Development Tools Site Related Forums       Site Related Discussions       Article Discussion       Poll Discussion       The Yak Corral Other Forums       SQL Server 6.5 \ SQL Server 7.0       Other Topics       MS Access       ClearTrace Support Forum Old Forums       CLOSED - General SQL Server       CLOSED - SQL Server 2005/Yukon  -------------------- Home Active Topics Frequently Asked Questions Member Information Search Page
 SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC
 This page was generated in 0.07 seconds.