473,412 Members | 2,096 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

data from Four table

i want a stock report from 4 tables
sales table consist of multiple rows of itemcode,itemname,qty,tdate
purchase table consist of multiple rows of itemcode,itemname,qty,tdate
stock table only one row of code and itemcode,itemname ,qty,
salesreturn table itemcode,itemname,qty,tdate
now i want to display data for selected date like below format
************************************************
code,itemname,openingstock,purchaseqty,stock atpresent(Purchase-sales),salesqty,salesreturn,closingstockqty
************************************************
when iam tryin with joins it will returns multiple rows/multiple qty
Thanks in advance
Jan 23 '12 #1
6 2710
Rabbit
12,516 Expert Mod 8TB
Sounds like what you want is an aggregate query. But you haven't given enough information for me to know either way.
Jan 23 '12 #2
C CSR
144 100+
Here's a query to get the data you want. Convert it to an Append Query for a report table with a ReportID corresponding to your list of stock items to separate reports (& create your "date" fields accordingly for all your tables).

This uses 3 tables: sr1Stock, sriSales & sr1Purchase, and their IDs are respectively, Stk_ID, SO_ID & PO_ID.

This uses the "sum" for sales across separate invoices and itemizes by Stock items and their related Purchase Orders.

Expand|Select|Wrap|Line Numbers
  1. SELECT sriStock.Item_ID, sriStock.ItemName, sriStock.Qty, sriPurchase.Qty, Sum(sriSales.Qty) AS SumOfQty
  2. FROM sriSales RIGHT JOIN (sriStock LEFT JOIN sriPurchase ON sriStock.Item_ID = sriPurchase.Item_ID) ON sriSales.Item_ID = sriStock.Item_ID
  3. GROUP BY sriStock.Item_ID, sriStock.ItemName, sriStock.Qty, sriPurchase.Qty;
  4.  

I gave you a query, but did not use it to do the append yet. See if this gives you the data you want, and let us know if you need further assistance.
Jan 24 '12 #3
thanks for reply but i need all sales qty(from sales table),purchase qty from purchase table,sales return qty from sales return table, opening qty from purchase qty-sales qty for selected date ,closing stock purchase -sales -sales return
Jan 26 '12 #4
Rabbit
12,516 Expert Mod 8TB
I'll say it again, you don't give us enough information to know what you want.
Jan 26 '12 #5
C CSR
144 100+
Hang in there. I've got a query to do what you want, but I'm reviewing an integrated update process that you'll need to refresh your starting inventory and provide tracking for current transanctions and subtotals as they occur within a given period (if you haven't given up on me). No reply necessary, I need the same configuration for something else that's similar anyway.
Jan 27 '12 #6
C CSR
144 100+
The query below won't make much sense without looking at the structure of the database for this problem and a basic process for conducting business based on your example. You hadn't presented me with much detail so I did the construction myself. Here we go!

Explanation: Upon opening the books, the Inventory Table has to be rejuvenated with the Closing-Inventory from the previous period and preserved as the Starting-Inventory for future period analysis (reports). In real-time, you would be dealing with transaction ids where tables are appended with new records constantly and Inventory is updated. So, for each transaction, a "dynamic inventory" would be updated by {Starting-Inventory + Purchases (PO) - Sales (SO)+ Returns (SR)}, and your Closing Inventory will equal the Dynamic Inventory at the end of any given period; that's where the Inventory is assigned as Starting-Inventory for the next period. By benefit, your Dynamic-Inventory can be queried from the results following the last recorded transaction or otherwise based on the results of a specific closing condition or report (see "Special consideration..." further down). Your function is going to look like this:

New (StartingInventory) = (ClosingInventory) = DynamicInventory = (StartingInventory plus PurchaseOrders plus SalesReturns minus SalesOrders).

For future reference, I may refer to {StartingInventory + PurchaseOrders} as "Opening Available Inventory" (OpenAvl_Inv). The following query will render a snapshot report for a single period using a date (ignoring dynamic inventory for now) based on the table structures that will follow below:

Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT Inv_Tbl.Item_ID, Inv_Tbl.ItemName, Inv_Tbl.Inv_Qty AS StartInv, PODATA.SumOfPO_Qty AS Purchases, nz([Inv_Tbl.Inv_Qty])+nz([PODATA.SumOfPO_Qty]) AS OpenAvl_Inv, SODATA.SumOfSO_Qty AS Sales, SRDATA.SumOfSR_Qty AS Returns, nz([SODATA.SumOfSO_Qty])-nz([SRDATA.SumOfSR_Qty]) AS Net_Sales, (nz([Inv_Tbl.Inv_Qty])+nz([PODATA.SumOfPO_Qty]))-(nz([SODATA.SumOfSO_Qty])-nz([SRDATA.SumOfSR_Qty])) AS Close_Inv FROM 
  3. ((Inv_Tbl LEFT JOIN (SELECT PO_Tbl.Item_ID, Sum(PO_Tbl.PO_Qty) AS SumOfPO_Qty, PO_Tbl.OrderDate, Transactions.TransDate FROM PO_Tbl INNER JOIN Transactions ON PO_Tbl.Trans_ID = Transactions.Trans_ID GROUP BY PO_Tbl.Item_ID, PO_Tbl.OrderDate, Transactions.TransDate HAVING (((Transactions.TransDate)=[close date] Or (Transactions.TransDate) Is Null))) AS PODATA ON Inv_Tbl.Item_ID = PODATA.Item_ID) 
  4. LEFT JOIN (SELECT SO_Tbl.Item_ID, Sum(SO_Tbl.SO_Qty) AS SumOfSO_Qty, SO_Tbl.SalesDate, Transactions.TransDate FROM SO_Tbl INNER JOIN Transactions ON SO_Tbl.Trans_ID = Transactions.Trans_ID GROUP BY SO_Tbl.Item_ID, SO_Tbl.SalesDate, Transactions.TransDate HAVING (((Transactions.TransDate)=[close date] Or (Transactions.TransDate) Is Null))) AS SODATA ON Inv_Tbl.Item_ID = SODATA.Item_ID) 
  5. LEFT JOIN (SELECT SR_Tbl.Item_ID, Sum(SR_Tbl.SR_Qty) AS SumOfSR_Qty, SR_Tbl.ReturnDate, Transactions.TransDate FROM SR_Tbl INNER JOIN Transactions ON SR_Tbl.Trans_ID = Transactions.Trans_ID GROUP BY SR_Tbl.Item_ID, SR_Tbl.ReturnDate, Transactions.TransDate HAVING (((Transactions.TransDate)=[close date] Or (Transactions.TransDate) Is Null))) AS SRDATA ON Inv_Tbl.Item_ID = SRDATA.Item_ID 
  6. GROUP BY Inv_Tbl.Item_ID, Inv_Tbl.ItemName, Inv_Tbl.Inv_Qty, PODATA.SumOfPO_Qty, nz([Inv_Tbl.Inv_Qty])+nz([PODATA.SumOfPO_Qty]), SODATA.SumOfSO_Qty, SRDATA.SumOfSR_Qty, nz([SODATA.SumOfSO_Qty])-nz([SRDATA.SumOfSR_Qty]), (nz([Inv_Tbl.Inv_Qty])+nz([PODATA.SumOfPO_Qty]))-(nz([SODATA.SumOfSO_Qty])-nz([SRDATA.SumOfSR_Qty])); 
  7.  
It may look daunting but its really pretty basic. The Outer query uses the data from 3 Inner queries (aliased as PODATA, SODATA and SRDATA) and then performs the calculations for Open "Available" Inventory, Net Sales and Closing Inventory. The query requests an input-date that is the basis for the desired daily demarc, past or present. Your results would be a list of Inventory Items displaying the following stats for each item: Item_ID, ItemName, StartInv, Purchases, OpenAvl_Inv, Sales, Returns, Net_Sales & Close_Inv.

You are going to need a main "Transactions" Table recording the "nature" of each input despite the fact that you have individual tables for separate types of transactions. This facilitates summing multiple entries of one type (POs, SOs or SRs) within the same period and presenting all types together (POs, SOs and SRs) within the same report, and on the same line per each inventory item. Here is an outcome possibility table for a report based on using the Inventory table for starting quantities, and linking it to the other 3 tables, showing the Date of each table's entries in the order of PO, SO, SR:

ItemID #1: null, 1/28/2012, 1/28/2012,
ItemID #2: 1/28/2012, 1/28/2012, 1/28/2012,
ItemID #3: 1/27/2012, 1/28/2012, 1/28/2012.

Without a Transaction table your results may be blended, as in example #3, or, where no transaction occurs on a given date within a particular table (POs, SOs or SRs), joining the Inventory table with the others for a report will force a rejection of any transactions contained in the other tables that do have entries for the requested date. In other words, since you have to maintain dated entries in your PO, SO and SR tables, a problem arises where your results would only include #1 and #2 as you query for dates across all three categories--the categories complying with the date 1/28/2012 in #3 would NOT be considered and the Inventory item would be missing.

The transaction table could be created as a temporary table while producing the report, but that's another exercise for discussion. Here are table definitions to better diagram where the data is being queried from:

Table definitions - (all IDs are numbers, and input Dates must go in and come out in the same format--I use shortdate in this case). There are other specifications to adhere to for input, but are not immediately mentioned here.

Transactions Table [Transactions]: Trans_ID, Item_ID, PO_ID, SO_ID, SR_ID, TransDate.

Inventory Table [Inv_Tbl]: Item_ID, ItemName, StartInv_Qty, OpenDate (and when fully implemented, Dyn_Qty).

Purchase Orders [PO_Tbl]: PO_ID, Item_ID, ItemName, PO_Qty, OrderDate, Trans_ID.

Sales Orders [SO_Tbl]: SO_ID, Item_ID, ItemName, SO_Qty, SalesDate, Trans_ID.

Sales Returns [SR_Tbl]: SR_ID, SO_ID, Item_ID, ItemName, SR_Qty, ReturnDate, Trans_ID (SO_ID is in this table for future reference to original SO).

Special consideration has to placed on the beginning of any given period (or new date) to carry over the previous period's Closing Inventory and prepare for the next, as illustrated in the function I spoke of at the top. We have not gone that far into your process of opening and closing the books, conducting updates necessary to reassign your starting quantities, and computing the dynamic changes in inventory during the given period. Obviously, trying to produce subsequent reports from different dates on the same starting inventory would be misconduct. You have the options of appending to the Inventory table the new date and closing data, or storing past data elsewhere and just updating the current records.

You asked for a report based on dates revealing all transactions, and I'm giving you a solution based on some existing and assumed business practices. You still have to choose (or at least explain to me) how you need to input/update the data per each transaction and how or when in the string of transactions you want to "jiggle" the dynamic and periodic updates to keep your inventory data stable. The answer provided here is a "single query" relying on the precise structure I made available and can be supplemented with other procedures to accommodate the issues that remain. Hope this has all been instructive.
Jan 29 '12 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Andrus Moor | last post by:
To reproduce: run the following code in IE 6 and right-click in table. Observed result: Error : invalid argument at line var row = table.insertRow(0); Expected result: new row must be...
2
by: Tonya | last post by:
Hi, i wanted to know how i could resolve the following error message: An unhandled exception of type 'System.ArgumentException' occurred in system.dll Additional information: The data grid...
0
by: hrh1818 | last post by:
What type of control would you suggest for use in entering numeric data in a 4 column by n row data entry table. The number of rows n can vary from 3 to 20 and will be detrmined at run time. The...
2
by: gaston | last post by:
Hi All I have three data bases with a table each one, what I want to do is to get the data from each table and insert it in a new data base table. The thing is that may be there is going to a...
0
by: Michael | last post by:
I am trying to insert the same set of data into two tables with the same schema. One table is used for processing, the other for audit purposes. I thought that I could use the data change table...
1
by: rahullko05 | last post by:
Hi, i am building a small forum site as my final year project & stuck in a very trivial problem. I have a table which are varchar type of data & i am trying to fetch data from table based on...
2
by: shimul | last post by:
Hi, Have table with data ( like a,b,c,d in column 1), want to read data from table and put in text box in continuous form. like tble name "tbltest" and textbox name "txtbox". now want to...
3
by: bluethunder | last post by:
Good day everyone, I'm having a hard time with my program on how to display the data from table to combo box. I have two tables that have been LEFT JOIN to have their relationship in the Data...
0
by: naveendb2dba | last post by:
while loading the PK COLUMN data into table I am getting the duplicate key in a table because of PK COLUMN having auto increment. My requirement is what ever data having the ORIGINAL TABLE that...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.