jerome.morris (11/5/2012)
Hi all, I was wondering if this is possible, I use the query below which is working great if be it a little slow as table is huge. I only want to return the top 20 worst offending Operator_Names from the queryHow do I do this, do I use count ?
SELECT Operator_Name, Docket_Id, Docket_Machine, Docket_Number, Docket_Status, Docket_EngineerName, Docket_Category, Docket_SubCategory, Duration,
Module, Section, Waittime, Monitor_Time, spare8, Docket_EngStart, Docket_EngFinish, Docket_DateRaised, Docket_Date, Contract
FROM DocketTB
WHERE (Docket_Status = 'CL') AND (Contract = '1') AND (Operator_Name IS NOT NULL) AND (Operator_Name NOT LIKE 'None')
The easiest way is to use ROW_NUMBER. You need to figure out what makes the top 20. I don't see an order by in your query but that is what will define the "top 20".
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/