Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Limit SQL Output in Excel

Posted on 2011-03-10
3
234 Views
Last Modified: 2012-05-11
I've got a Microsoft Query set up between a sql database and excel 2010 that I'm trying to filter out some information.  Attached is a copy of the report in its current state.  You'll see that the attached customer has two jobs in my system, all of which have multiple steps (Work Centers).  What I'd like to obtain is limiting the output of this script so that it only shows the first Work Center, which varies depending on the job.  Is this possible?  Attached is my SQL Code generated by Excel.  I tried using LIMIT 1 on the function at the end, but it tells me the code has errors when I apply it. "Job.Job" is the field that contains the job number, which is how I would like to limit it.  

Thank You for your help!

example.pdf
SELECT Job.Job, Job.Order_Date, Job.Customer, Job.Customer_PO, Job.Part_Number, Job.Customer_PO_LN, Job.Order_Quantity, Job.Status, Job.Sched_Start, Job.Sched_End, Job_Operation.Work_Center, Job_Operation.Status
FROM PRODUCTION.dbo.Job Job, PRODUCTION.dbo.Job_Operation Job_Operation
WHERE Job.Job = Job_Operation.Job AND ((Job.Status='Active') AND (Job_Operation.Status<>'C'))
ORDER BY Job.Customer

Open in new window

0
Comment
Question by:Kyle Witter
  • 2
3 Comments
 
LVL 7

Expert Comment

by:andymacf
ID: 35095398
Would the first work centre be the most recent one, if so, you could set your query to look for 'max' value on the relevant field and this will always pull in the first event.
0
 
LVL 1

Author Comment

by:Kyle Witter
ID: 35095440
The first work center is the location that the job is currently at in production.  This is the line that I would like to keep.  I guess I don't understand exactly how to set a max value to limit the output, though.

Do you have an example?  Thank you!
0
 
LVL 7

Accepted Solution

by:
andymacf earned 500 total points
ID: 35096818
Difficult to give you an example right away as I am away from my pc, but try this. In your SQL, try wrapping the value 'max(your value)… Select max(value) from
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question