473,395 Members | 1,675 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,395 software developers and data experts.

select unique and return related table

Microblitz
This Code selects a unique entry of the Manufacturing Order.

Expand|Select|Wrap|Line Numbers
  1. DECLARE @suffix NVARCHAR(8)
  2. DECLARE @DateStart NVARCHAR(12)
  3. DECLARE @DateEnd NVARCHAR(12)
  4.  
  5. SET @suffix = '/M'
  6. SET @DateStart = '01/05/2013'
  7. SET @DateEnd = '08/05/2013'
  8.  
  9. SELECT a.*  from  ManufacturingOrders a 
  10. INNER JOIN
  11. (SELECT DISTINCT  ManufacturingOrderId FROM ManufacturingOrders) AS b
  12. ON a.ManufacturingOrderId = b.ManufacturingOrderId
  13. ORDER BY ManufacturingOrderId
  14.  
I need to use that to select related information from this query.

Expand|Select|Wrap|Line Numbers
  1. SELECT     ManufacturingOrders.QuantityMade AS Quantity_Made, Products.ProductId, Classifications.ClassificationId, Products.ProductDescription, 
  2.                       ManufacturingOrders.QuantityOutstanding AS Outstanding, ManufacturingOrders.DueDate, ManufacturingOrders.ReleaseDate, 
  3.                       ManufacturingOrders.ManufacturingOrderId, Inventory.EffectiveDate, Inventory.CreatedDate, Inventory.LotNumber, Inventory.WorkInProgress, 
  4.                       Inventory.QuantityFilled
  5.  
  6. FROM       ManufacturingOrders INNER JOIN
  7.                       Products ON ManufacturingOrders.Product = Products.Product INNER JOIN
  8.                       Classifications ON Products.Classification = Classifications.Classification INNER JOIN
  9.                       Inventory ON ManufacturingOrders.ManufacturingOrder = Inventory.ManufacturingOrder AND Products.Product = Inventory.Product
  10. WHERE     (RIGHT(Products.ProductId, 2) = UPPER(@suffix)) AND (dbo.wfn_GetSimpleDate(Inventory.CreatedDate) BETWEEN @DateStart AND @DateEnd)
  11. ORDER BY Classifications.ClassificationId, ManufacturingOrders.ReleaseDate DESC
Can anyone suggest how I can tack these two pieces of code together without dropping data. Essentially I need to get the data from the second query ONLY if its the first occurance of the Manufacturing order so I can return the correct requested order amount as there are multiple instances of the Manufacturing order table (I know somebody (not me) messed up!)
May 8 '13 #1
3 1594
Rabbit
12,516 Expert Mod 8TB
I'm not sure I understand your question. Some sample data and results would help.
May 8 '13 #2
I rewrote this and solved it.
May 17 '13 #3
Rabbit
12,516 Expert Mod 8TB
Glad you got it fixed. Can you post your solution in case someone else runs into the same situation?
May 17 '13 #4

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

Similar topics

2
by: Fons Roelandt | last post by:
Heelo, I have to Update all fields from a table with the values of a related table, i've tried some querys i found on the internet, but nothing seems to word, i even tried to lookup the value...
3
by: Gerry Abbott | last post by:
Hi all, Im using the after update event of a field from a bound form to add records using the recordset object, to a related table. However i'm getting the 3201 error, telling me I must have a...
2
by: jaYPee | last post by:
At last I have found the problem why I can't get to work w/ importrow. The fact is that I'm trying to import data to related table. But after importing data the foreign is blank. So thats why the...
3
by: Kall, Bruce A. | last post by:
I've look for a solution to this, but have only been able to find solutions to delete duplicate entries in a table by deleting entries not returned by SELECT DISTINCT. What sql should I use to...
3
by: MLH | last post by:
Generally, I do not monkey with renaming controls on forms whose name, by default, matches the name of their related table fields. But I noticed the following today If IsNull(Me!VColor) Then...
2
by: mcyi2mr3 | last post by:
hi all ive been looking on the mysql site but i cant find the syntax to set a collumn in an existing table to be unique. could someone please give an example of how to do this. i believe it...
4
by: Michael R | last post by:
Or is it not necessary to have that option on the related table field, as the primary table indexed field does that job? And is it a necessity to have the related table field to be indexed if I...
2
by: John Bailo | last post by:
I can say SELECT "HELLO" and it returns HELLO But say I want to return a table
2
by: shahzeb143 | last post by:
I would like to select strings from a table and return them as an array For example, select new_array(name) from my_tbl would return String { name1, name2, name3, etc } Is this possible...
0
by: JeremyI | last post by:
Working in Access 2003 with Access 2000 file format. I'm trying to set up a form with a six-page tab control, three pages of which contain subforms bound to a table that has a 1-to-1 relationship...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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,...

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.