Query to find when a total is hit

We are trying to get some statistics on our Inventory people to see if they 
are issuing material to work orders on time.  My work order table has a 
field that shows the last transaction date of the order, but if Inventory 
issue all the material then has to issue more because of scrap later they 
get dinged as being late.

We have a Transaction History table that shows every issue however I don't 
know a good way to find out when the total number of needed parts was 
reached.  For Example I am creating a shop order that needs 3 parts, 50 of 
each:

ShopOrder    PartNeeded    Due Date    Due Qty
1000001        ABC                5/1/2010        50
1000001        DEF                5/1/2010        50
1000001        GHI                5/1/2010        50

Shop Order    PartIssued    DateIssued    IssuedQty
1000001        ABC                4/1/2010        25
1000001        DEF                4/1/2010        25
1000001        GHI                4/1/2010        25
1000001        ABC                4/20/2010        25
1000001        DEF                4/20/2010        25
1000001        GHI                4/20/2010        25
1000001        GHI                5/2/2010        10

In the data above you can see that all the needed parts were issued by 4/20 
so Inventory did their job, however because of whatever reason they had to 
issue 10 extra on 5/2 a day after the due date.  When I use MAX for the date 
issue it will look like Inventory was late.  I need something that total 
from first to last issue and find the date when the 50 for any given part 
was reached. 



0
Jordan
5/27/2010 8:43:38 PM
sqlserver.programming 1873 articles. 0 followers. Follow

1 Replies
347 Views

Similar Articles

[PageSpeed] 52

>  I need something that total from first to last issue and find the date 
> when the 50 for any given part was reached.

Below is one method:

CREATE TABLE dbo.WorkOrder
(
	ShopOrder int NOT NULL,
	PartNeeded char(3) NOT NULL,
	DueDate date NOT NULL,
	DueQty int NOT NULL,
	CONSTRAINT PK_WorkOrder PRIMARY KEY (ShopOrder, PartNeeded, DueDate)
);

INSERT INTO dbo.WorkOrder
VALUES
	(1000001,'ABC','2010-05-01',50),
	(1000001,'DEF','2010-05-01',50),
	(1000001,'GHI','2010-05-01',50),
	(1000002,'ABC','2010-05-01',50),
	(1000002,'DEF','2010-05-01',50),
	(1000002,'GHI','2010-05-01',50);

CREATE TABLE dbo.TransactionHistory
(
	ShopOrder int NOT NULL,
	PartIssued char(3) NOT NULL,
	DateIssued date NOT NULL,
	IssuedQty int NOT NULL,
	CONSTRAINT PK_TransactionHistory PRIMARY KEY (ShopOrder, PartIssued, 
DateIssued)
);

INSERT INTO dbo.TransactionHistory
VALUES
	(1000001,'ABC','2010-04-01',25),
	(1000001,'DEF','2010-04-01',25),
	(1000001,'GHI','2010-04-01',25),
	(1000002,'ABC','2010-04-01',25),
	(1000002,'DEF','2010-04-01',60),
	(1000001,'ABC','2010-04-20',25),
	(1000001,'DEF','2010-04-20',25),
	(1000001,'GHI','2010-04-20',25),
	(1000001,'GHI','2010-05-02',10);
GO

SELECT
	WorkOrder.ShopOrder,
	WorkOrder.PartNeeded,
	WorkOrder.DueDate,
	DailyFilledOrders.DateIssued
FROM
	(SELECT
		ShopOrder,
		PartIssued,
		DateIssued,
		(SELECT SUM(IssuedQty)
		FROM dbo.TransactionHistory prev
		WHERE
			prev.ShopOrder = curr.ShopOrder
			AND prev.PartIssued = curr.PartIssued
			AND prev.DateIssued <= curr.DateIssued) AS TotalIssuedQty
	FROM dbo.TransactionHistory curr
	GROUP BY
		ShopOrder,
		PartIssued,
		DateIssued) AS DailyFilledOrders
RIGHT JOIN dbo.WorkOrder ON
	WorkOrder.ShopOrder = DailyFilledOrders.ShopOrder
	AND WorkOrder.PartNeeded = DailyFilledOrders.PartIssued
	AND WorkOrder.DueQty <= DailyFilledOrders.TotalIssuedQty
	AND WorkOrder.DueDate >= DailyFilledOrders.DateIssued;


--NULL DateIssued indicates missed DueDate
ShopOrder	PartNeeded	DueDate	DateIssued
1000001	            ABC                        2010-05-01    2010-04-20
1000001	            DEF                        2010-05-01	    2010-04-20
1000001	            GHI                        2010-05-01	    2010-04-20
1000002	            ABC                        2010-05-01    NULL
1000002	            DEF                        2010-05-01    2010-04-01
1000002	            GHI                        2010-05-01    NULL

-- 
Hope this helps.

Dan Guzman
SQL Server MVP
http://weblogs.sqlteam.com/dang/

"Jordan" <none@here.com> wrote in message 
news:#I6$N0d$KHA.3880@TK2MSFTNGP04.phx.gbl...
> We are trying to get some statistics on our Inventory people to see if 
> they are issuing material to work orders on time.  My work order table has 
> a field that shows the last transaction date of the order, but if 
> Inventory issue all the material then has to issue more because of scrap 
> later they get dinged as being late.
>
> We have a Transaction History table that shows every issue however I don't 
> know a good way to find out when the total number of needed parts was 
> reached.  For Example I am creating a shop order that needs 3 parts, 50 of 
> each:
>
> ShopOrder    PartNeeded    Due Date    Due Qty
> 1000001        ABC                5/1/2010        50
> 1000001        DEF                5/1/2010        50
> 1000001        GHI                5/1/2010        50
>
> Shop Order    PartIssued    DateIssued    IssuedQty
> 1000001        ABC                4/1/2010        25
> 1000001        DEF                4/1/2010        25
> 1000001        GHI                4/1/2010        25
> 1000001        ABC                4/20/2010        25
> 1000001        DEF                4/20/2010        25
> 1000001        GHI                4/20/2010        25
> 1000001        GHI                5/2/2010        10
>
> In the data above you can see that all the needed parts were issued by 
> 4/20 so Inventory did their job, however because of whatever reason they 
> had to issue 10 extra on 5/2 a day after the due date.  When I use MAX for 
> the date issue it will look like Inventory was late.  I need something 
> that total from first to last issue and find the date when the 50 for any 
> given part was reached.
>
> 
0
Dan
5/28/2010 12:47:57 PM
Reply:

Similar Artilces:

Timer for Queries?
Does anyone know of a macro or add-on that I could use as a simple timer for queries? I don't like to use the CPU time in the Task Manager because of it's inaccuracy when not receiving full CPU usage. THanks for any suggestions -- cmungs Exactly what are you trying to accomplish? Are you trying to cause a query to run automatically every so often? If so, you will need to use the timer event on a form to do that. -- Lynn Trapp Microsoft MVP (Access) www.ltcomputerdesigns.com "cmungs" <cmungs@discussions.microsoft.com> wrote in message news:88EC7019-045F-4EF...

Multiplying Columns in total
How would one go about multiplying Column A in sheet1 with Column A i sheet2 to make a new column in sheet3 -- Yavaro ----------------------------------------------------------------------- Yavarow's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=1608 View this thread: http://www.excelforum.com/showthread.php?threadid=27534 =Sheet1!A1*Sheet2!A1 "Yavarow" <Yavarow.1f7jxc@excelforum-nospam.com> wrote in message news:Yavarow.1f7jxc@excelforum-nospam.com... > > How would one go about multiplying Column A in sheet1 with Column A in > sheet...

Finding on Version of SP installed
Hi I want to what are the possiblities of finding Which Version of SP installed in Exchange2000 server?? On Sat, 24 Sep 2005 03:33:01 -0700, "swaminathan" <swaminathan@discussions.microsoft.com> wrote: >Hi > > I want to what are the possiblities of finding > Which Version of SP installed in Exchange2000 server?? > Open up Exchange System Manager and drill down the left pane to the servers. Look in the right pane and you will see the servers in that AG. You may have to expand the columns a bit. just as Mark said drill down to servers, select a server...

Erratic results from query criteria
I am getting different results from running the same query with the same selections. One moment it is all behaving as expected, the next it has gone haywire. (I have done what appears to me to be EXACTLY what I have done in another database, where it works perfectly every single time.) In a query I have, amongst others, the following fields: Category SubCategory Company I want to be able to select any OR ALL of the relevant fields. I have the following criteria: Like "*"&[Type Category otherwise leave blank for ALL]&"*" Like "*"&a...

Update Query ?
Is there a way to 1) Assign events when adding in data thru an update query for example if you append a bunch of data into a table could you then do some kind of an update query to say if there is an initial event and no others tag this one Renewal 1 etc.. the only real data you have to go on would be Customer A and the total amt .. the event, renewal event and the delta would all need to be added in example: Say Customer A comes in with an initial deal then Customer A renews their deal So, the data would look like when you're done.: Year Custo...

design query match anywhere?
In the design query I want to match the letters "ABC" anywhere in the column 'description'. I could not get instr to work by using: InStr(description, "ABC")) > 0 How else can I match ABC (upper and lowercase) to anywhere in my 'description' column? Thanks! Are you saying you put that InStr bit as a criteria under your Description field in the query designer? Try putting Like "*ABC*" as the criteria instead. Alternatively, you could add a computed field to the query InStr([Description, "ABC") and then put >0 as the ...

Unexpected Error- Running Advance Find Query
I am getting a message that says "Unexpected Error An Error has occurred" when I am running an advanced find query on two custom entities. It seems to be when I have certain custom fields included in my view that the query errors out. Any help on this would be greatly appreciated. Thanks so much. Just wanted to add that I seem to get errors when there is a 0.00 amount in these fields... "TJ" wrote: > I am getting a message that says "Unexpected Error An Error has occurred" > when I am running an advanced find query on two custom entities. It se...

pass through query
If a combobox is populated by a pass-through query, does it requery every time the form is closed and reopened? Thanks, Sam Yes. John Spencer Access MVP 2002-2005, 2007-2010 The Hilltop Institute University of Maryland Baltimore County Sam wrote: > If a combobox is populated by a pass-through query, does it requery every > time the form is closed and reopened? > Thanks, > Sam ...

a count field in a query?
Hello, I have a query in which I would like to create a field which increments by 1 for each record selected, so if there are 10 records selected by the query, this column would show numbers 1 to 10. Ideally I would like to have some text in front of each number, say invoice1, invoice2 etc. From a previous posting I realise that this is frowned upon but it would be the simplest solution for my problem! How can I do this? Thanks Geoff On Mon, 03 Dec 2007 08:54:00 +0000, Geoff Cox <<>> wrote: >Hello, > >I have a query in which I would like to create a field which >...

Location of Grand Total in Pivot table
Is the a way to show the Grand total next to the selected Field as opposed to the right now column ( I am using a file that had data results by Date)? You can not move the grand totals. They is where they is and that's where they stays... -- HTH... Jim Thomlinson "Rosemary" wrote: > Is the a way to show the Grand total next to the selected Field as opposed to > the right now column ( I am using a file that had data results by Date)? ...

Saving Username and Pass with Web Queries
I am pulling data from a website that requires you to provide a usernam and password everytime you visit the site. Excel has cachin capabilities, but everytime you close excel and try and open up th spreadsheet again, it can't login. What is the fix for this? Thanks, Hend -- Message posted from http://www.ExcelForum.com Bump! --- Message posted from http://www.ExcelForum.com/ ...

Birthday query for many children in one record
I have a database for the church, it has one main flat table only. Each record for the parents have field for child1 name, child1birthday, child2 name, child2birthday, child3 name, child3birthday - up to 5 children. I am having difficulty trying to get a report to list the birthdays of the children like this parent name, child 1 name, child 1 birthday month etc. so you get something like this:- Parent John Smith, child Mary Smith January 3 Parent Fred Jones, child Bert Jones March 4 Parent John Smith, child Jane Smith March 6 Parent Harry Brown, child Jane Brown March 6 Parent Bert Taylor,...

Ctrl+PgDn disabled after Find and Replace
I have Windows 7 and Office 2003. After using Find and Replace in a Word document, I want to scroll down a page at a time using Crtl+PgDn. In stead of scrolling, I keep getting a message "Word has reached the end of the document. Do you want to continue searching at the beginning?" every time I try. And then it does this for every document I have open in Word. How do I stop this and turn off the Find and Replace after I have used it? Ctrl+PgDn runs the BrowseNext command; what that command does depends on what was previously done in Word (as you have noticed). Do the...

Unresponsive Query Wizard
Hi there, I have an Excel 2003 user who is using a spreadsheet that pulls data from our SQL server. When he opens it and refreshes the data it is fine, it pulls the current data, but when he tries to edit the query, the Query Wizard does not appear, he can see it on the task bar, but when he switches focus using task manager everything is greyed out and nothing works. I have tested the file from my computer and it is fine, which suggests a problem with his machine or installation. Does anyone have any ideas? Cheers, Steve Dooza wrote: > Hi there, > I have an Excel 2003 user who...

Another simple query
Dear all, I have a table that contains first names and last names in different fields. Is there any way to write a query that will give as a result the first name and last name in the same field? I hope this makes sense. Thanks in advance! SELECT [last_name_field] & ", " & [first_name_field] AS whole_name FROM [your_name_table] Change the field and table names to whatever your actual fields and tables are. Cheers, Jason Lepack On Apr 23, 9:47 am, Homer <peter.a.r...@googlemail.com> wrote: > Dear all, > > I have a table that contains first names an...

Finding the end of 4 week
Hello, I have given the task of preparing a time sheet with 4 weekly blocks. The very first block will start on the first monday of a month and go on for 4 weeks with ending on sunday. Then each further block will start with mondays (after 4 weeks). My problem is finding the end of 4 week and then the monday. To add to the problem each 4 week must be on a seperate sheet and would go for a year. Thanks for your help. If your start date is in cell A1 of sheet1, then the ending date is =A1+27 formatted for date. For the next sheet, use for the start date =Sheet1!A1+28 for the end dat...

Query query
I am trying to create a new field in which it shows the sum total of 10 fields (Charge Time, Charge Time 2, Charge Time 3, etc.); what is the easiest way to do this? -- Joe NewFieldName: [Charge Time] + [Charge Time 2] + [Charge Time 3] .... etc -- Good Luck BS"D "joet5402" wrote: > I am trying to create a new field in which it shows the sum total of 10 > fields (Charge Time, Charge Time 2, Charge Time 3, etc.); what is the easiest > way to do this? > -- > Joe I tried this, and it doesn't work. Is there something I'm forgetting? -- Joe ...

group by query trouble
I'm trying to run a query that counts the number of people with hemoglobin of type SS, type SC, and then all others. There are about 12 different kinds of types. Basically I want a count for SS, a count for SC, and then a count that totals all the others into one count. Hopefully that makes sense. I'm using group by for the SS and SC which works great, but I'm not sure how to tell it to add up the others. I'm not a big fan of nested IIf statements, but this should work after you put in the proper field and table names: SELECT IIf([Hemoglobin]="SC","SC&...

Find value in column and associate result to it
Excel 2003: I need to search a value in worksheet (2) that exists in worksheet (1), confirm if it status, in the same row but another column, is "ok" or "not ok" and associate a result for the search ("yes" if "ok" or "no" if "not ok"). But in worksheet (2) there are more than one result for each search. Example: worksheet 1: | worksheet 2: column A | column A column B HOME | HOME---------------ok CAT | HOME--------------not ok DOG | ...

To Query or not to Query??
Hello all - I'm a newbe to Access but have made great progress. I'm using Acess 2003. The db is up and running prefectly. Now I need to tackle the reporting. I have seen posts about reports and queries and am a little confused. Do I need to create a query to run my reports off of? I have a tabbed subform in the main form. There are seven tabs breaking up all the services we provide. Like "Promo Items", "Leads", "Client Printed Material","Internal Print Material" and so on. The main form has the User, Branch and Marketing Rep. I need to...

Dynamic Query
Hi! I am trying to dynamically modify my pass-through query containing a procedure call with 2 parameters. When I run my access app, I get this error: "Object or provider is not capable of performing reuqested operation." Below is my access code: Dim varItem As Variant Dim strSQL As String Dim cat As ADOX.Catalog Dim cmd As ADODB.Command Dim strMyDate As String, dtMyDate As Date dtMyDate = CDate([Forms]![ySalesHistory]![Start Date]) strMyDate = Format(dtMyDate, "yyyymmdd") strSQL = "procCustomerSalesandPayments '" & s...

Portfolio Manager displays cost with the wrong totals
I have Money 2006 and I set up my investments in portfolio manager. The cost totals for my investments do not add correctly. I don't have a massive portfolio so we are only talking about 2-3 mutual funds with a broker. Initial purchases and subsequent purchases were fine. Everything totaled and cross footed. But, that all changed when I partially sold them to pay my son's college tuition. Ex: Mutual fund Cost Market Value Fund ABC $500 $625 Fund 123 $1000 $1250 Total $1750 ...

Message Totals on Group Headers
Hi, In Outlook 2007, I have mail messages arranged in groups (Today, Yesterday, etc.). How can I get each group to display the total # of messages in the heading of each group? I'm pretty sure I used to have this, but it's gone now and I can't figure out how to re-enable. Thank you in advance for any assistance. "GTifeld" <GTifeld@discussions.microsoft.com> wrote in message news:AA988142-B67F-4BE1-BF30-63CF9D8475A5@microsoft.com... > In Outlook 2007, I have mail messages arranged in groups (Today, Yesterday, > etc.). How can I get each grou...

Finding amounts on different worksheets
Help please ..... I have been given the task of keeping the accounts [on excel] in order. The business has the sales client name and figures listed per month on different worksheets. When a payment comes in for a specific amount, it would be very useful to go to a function that could search every worksheet. [All I seem to be able to do is the methodically do a 'find' on every worksheet] Is there any way in which the FIND can be used to search every worksheet? try right click on sheet tab>select all sheets>edit>find>joe prospect>values -- Don Guillett SalesAi...

Linking tables in a query
I have a database that contains information on a certain number of individuals during different session. Table 1 'tbl_Tracking_Form1' has information on sessions 2,4 and 6. Table 2 'tbl_Tracking_Form2' has information on sessions 1,3 and 5. Table 3 'tbl_General_Info' has demographic information on all the individuals (those who will eventually attentd sessions 1,2,3,5,5 and 6). I need to create two reports. One (Report1) should display all the information on the individuals during session 2, 4 and 6 and another(Report2) that displays all the information on the i...