Top n Percent Equivalent

Hello All,
I would like to know what is the equivalent of Top n Percent in Oracle sql 11g.
Here is my requirement:
I have to find stores contributing top 20% of sales:
Store
Sales
Percetage
ABC
200
(200/380)*100=52%
XYZ
100
(100/380)*100=26%
PQR
50
(50/380)*100=13%
dddd
20
(20/380)*100=5%
rrrr
10
(10/380)*100=2%
In the above example I have to get only store ABC as this store alone is contributing more than Top 20%
If I change the requirement to Top 70% I have to get store's ABC and XYZ.
Any help would be highly appreciated.
Thanks,
MC

Hi,
You can do that with analytic functions.
Since I don't have a test version of your table, I'll use the scott.emp table to illustrate
WITH got_totals AS
    SELECT    ename
    ,         sal
    ,         SUM (sal) OVER ( ORDER BY       sal DESC
                               RANGE BETWEEN  UNBOUNDED PRECEDING
                                     AND      1E-9      PRECEDING  -- arbitrary small number
                             ) AS running_total
    ,         SUM (sal) OVER ()            AS grand_total
    FROM      scott.emp
SELECT   ename
,        sal
FROM     got_totals
WHERE    NVL ( running_total
             , 0
             ) / grand_total   < .2     -- .2 means 20%
ORDER BY  sal DESC
With .2 in the WHERE clause, this produces the following output
ENAME             SAL GRAND_TOTAL RUNNING_TOTAL
KING             5000       29025
FORD             3000       29025          5000
SCOTT            3000       29025          5000
If you change the number in the WHERE clause to .1, you'll get KING alone, since KING's sal by itself accounts for more than 10% of the grand total (29025).
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for your table, and the query above as adapted for your table.
Point out where that query is producing the wrong results, and explain, using specific examples, how you get the right results from the given data in those places.
See the forum FAQ: https://forums.oracle.com/message/9362002#9362002

Similar Messages

  • Oracle 10g Select Top 100 Percent

    Hello
    How to convert MS sql 2008 select top 100 query Oracle PL/SQL ? MY sample MSSQL select query
    SELECT TOP (100) PERCENT dbo.Operations.OpID, dbo.CompanyInfo.Name AS CompanyName, dbo.CustomerInfo.SubscriberNo, dbo.CustomerInfo.FirstName,
    dbo.CustomerInfo.LastName, dbo.Operations.OpDate, dbo.Operations.BillCount, dbo.Operations.TotalAcceptedCash, dbo.Operations.KioskID,
    dbo.Operations.ReceiptNo, dbo.Operations.KioskOpID, dbo.KioskInfo.Name AS KioskName, dbo.Operations.TotalBill, dbo.Operations.TotalPayBack,
    dbo.CompanyInfo.CompanyID, dbo.Operations.ConfirmedRecord, dbo.PayMethod.ACK AS PayMethod
    FROM dbo.Operations INNER JOIN
    dbo.CustomerInfo ON dbo.Operations.SubscriberNo = dbo.CustomerInfo.SubscriberNo INNER JOIN
    dbo.CompanyInfo ON dbo.Operations.CompanyID = dbo.CompanyInfo.CompanyID INNER JOIN
    dbo.KioskInfo ON dbo.Operations.KioskID = dbo.KioskInfo.KioskID INNER JOIN
    dbo.PayMethod ON dbo.Operations.PayMethodID = dbo.PayMethod.PayMethodID
    ORDER BY dbo.Operations.OpDate DESC

    Hi,
    Please read SQL and PL/SQL FAQ
    Additionally when you put some code please enclose it between two lines starting with {noformat}{noformat}
    i.e.:
    {noformat}{noformat}
    SELECT ...
    {noformat}{noformat}
    From what I have found on MS SQL documentation it seems that TOP keyword limits the output to a specified percentage of total number of rows. In your case, having specified 100, you are returning 100% of rows.
    So you can simply remove *TOP (100) PERCENT*
    Regards.
    Al                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Sybase "Top (n) percent" does not work, any suggestions?

    Hi All,
    I want to select a percentage of records in Sybase. I can only use "SELECT TOP n" to select n rows. If I want to select 100% of the rows in SQL I use "SELECT TOP (100) PERCENT", Sybase does not recognize the syntax.
    Does anyone know if this is possible in Sybase? What is the syntax in Sybase?
    Thank you in advance.
    Regards,
    Reshma
    Please Vote as Helpful if an answer is helpful and/or Please mark Proposed as Answer or Mark As Answer when question is answered

    Try : SELECT TOP 100 PERCENT ...
    and find a right forum to ask question related Sybase. It is not the same product now.

  • Charts - Display Top Percent and Legend Layout Questions

    I have two pie charts with problems. In one, I've set the Options Legend Layout to Both, Top Percent to 85, and the legend displays the top 85 percent with a count for each group, but the total of the count column is still the grand total, not the total of the 85 percent.
    In the second pie chart, I have the same settings, Top Percentage and Options Legend Layout Both, but the count displays as dollar values, eventhough the field is a date field.
    Does anyone know how to correct these problems?
    Thanks!
    Robin

    hi Robin,
    you've got 2 options:
    a) you can use the cross-tab method that i mentioned before...a top N in the cross tab will show a percentage that is based on the whole record set as opposed to the N values...this is different than the chart legend percentage
    b) if you are willing to show the percentage that is based on the whole record set in the chart labels instead, you can  do the following...
    if you have an On Change Of value of "country" and the summary is "sales", then create a new formula called "chart title" that has syntax similar to
    {Customer.Country} +  chr(10) + totext(PercentOfSum ({Customer.Last Year's Sales}, {Customer.Country}))
    now change the chart On Change Of to your new formula. the percentage based on the whole record set will be shown in the chart labels.
    cheers,
    jamie
    Edited by: Jamie Wiseman on Nov 25, 2009 1:34 PM
    Edited by: Jamie Wiseman on Nov 25, 2009 1:35 PM

  • Select top 10 percentage

    Hi,
    I want to get the top 10% of salaries in employees table. But I got error:
    SQL> select top 10 percent salary
      2  from employees
      3  order by salary desc;
    ORA-00923: FROM keyword not found where expectedHow can I get the top 10% percent?
    Thanks a lot

    Hi,
    998093 wrote:
    ... What if I want to get, for example, the employees who are in the top 12% of the salaries? here we cannot use deciles (maybe we can but it won't be very nice).Actually, you can. How nice it will be depends on your data and your exact requirements.
    Earlier, we said that the top 10% was the 10th of 10 buckets.
    We could say that the top 12% is the last 12 of 100 buckets:
    WITH     got_tenth     AS
         SELECT     last_name, salary
         ,     NTILE (100) OVER (ORDER BY salary)     AS hundredth
         FROM     hr.employees
    SELECT       last_name, salary
    FROM       got_tenth
    WHERE       hundredth     > 100 - 12
    ORDER BY  salary     DESC
    ;I won't clutter up this message by showing the results for every query; I'll just report the total number of rows. The query I posted earlier (for the top 10%) produced 10 rows of output; the query immediately above produces 12. That's starting to bother me. There are 107 rows in hr.employees. (They all have a salary; don't forget to deal with NULLs in general.) The top 10% should contain 107 * .1 = 10.7 rows. Of course, this has to be rounded to an integer, so it would have been a little better if the top 10% showed 11 rows (since 11 is closer to 10.7 than 10 is), but it's not a real big problem. Likewise, the top 12% should have 107 * .12 = 12.84 rows, so 13 rows of output might be better, but 12 rows isn't too bad.
    Now say we want to simplify the condition "WHERE     hundredth     > 100 - 12". Instead of taking the last 12 buckets in ascending order, let's take the first 12 buckets in descending order:
    WITH     got_tenth     AS
         SELECT     last_name, salary
         ,     NTILE (100) OVER (ORDER BY salary DESC)     AS hundredth
         FROM     hr.employees
    SELECT       last_name, salary
    FROM       got_tenth
    WHERE       hundredth     <= 12
    ORDER BY  salary     DESC
    ;The result set now contains 19 rows! Why? Because NTILE puts extra items (when there are extras) in the lower-numbered buckets. When there were 10 buckets, then buckets 1 trough 7 had 11 items each, and buckets 8 through 10 had 10 items. We were only dispolaying bucket #10, so we only saw 10 items. Now that there are 100 buckets, buckets 1 through 7 will have 2 items each, and buckets 8 through 100 will have 1 item each. When we numbered the buckets in ascending order, and took the last 12 buckets, we wound up with 12 * 1 = 12 rows, but when we numbered the buckets in descending order and took the first 12 buckets, we got (7 * 2) + (5 * 1) = 19 rows.
    When you have R rows and B buckets, and R/B doesn't happen to be an integer, then NTILE will distribute the rows as equally as possible, but some rows will have 1 item more than others. When the ratio R/B is high, that might not be very significant, but when R/B gets close to 1, then you have situations like the one above, where the bigger buckets, although they have only 1 more item than the smaller buckets, are twice as big. Even worse is the situation where R/B is less than 1; then the last buckets will have 0 items.
    So, as you noticed, NTILE isn't a good solution for all occasions. Here's a more accurate way, using the analytic ROW_NUMBER and COUNT functions:
    WITH     got_analytics     AS
         SELECT     last_name, salary
         ,     ROW_NUMBER () OVER (ORDER BY  salary  DESC)     AS r_num
         ,     COUNT (*)     OVER ()                                AS n_rows
         FROM     hr.employees
    SELECT       last_name, salary
    FROM       got_analytics
    WHERE       r_num / n_rows <= 12 / 100
    ORDER BY  salary     DESC
    ;This produces 12 rows.
    If you want 13 rows (because 107 * .12 = 12.84 is closer to 13), then you can change the main WHERE clause like this:
    WITH     got_analytics     AS
         SELECT     last_name, salary
         ,     ROW_NUMBER () OVER (ORDER BY  salary  DESC)     AS r_num
         ,     COUNT (*)     OVER ()                                AS n_rows
         FROM     hr.employees
    SELECT       last_name, salary
    FROM       got_analytics
    WHERE       r_num     <= ROUND (n_rows * 12 / 100)
    ORDER BY  salary     DESC
    ;

  • [Desktop] Shuffle within top quarter of popular posts

    Hi Guys, I would like see an enhanched shuffle features which only shuffles in the top 25% percent songs based on popularity. For example, I am a big fan of Dire Straits and they have produced a ton of songs, many tracks of the same song in a different setting, e.g. live in Dublin, America, extended versions, etc. Therefore I sometimes have two times the same song in a different version. It would be great to have a shuffle function which only picks tracks from the top 25% of a specific artist, so the more known and popular songs are played. This would also be perfect when you stumble on an artist you have'nt heart of before, and you want to explore his repertoire. What do you guys think of the idea? Cheers,Fokko

    Updated: 2015-07-17Hi and thanks for your contribution! A similar idea has also been suggested here:
    https://community.spotify.com/t5/Live-Ideas/Desktop-Playlists-Shuffle-through-top-20-30-50-songs-of-artist/idi-p/1068855
    Add your kudos and comments there please!

  • How can I view the USMT recovery key in SQL report

    Hello all,
    Can anyone help me to provide sql query for below link… What I am looking is Just to create a report with all computers that has computer association any type with the recovery key information.
    http://www.windows-noob.com/forums/index.php?/topic/1763-how-can-i-view-the-usmt-recovery-key/
    I have tried below but not working so looking for help…..
    SELECT     TOP (100) PERCENT dbo.v_StateMigration.SourceName, dbo.v_StateMigration.SiteCode, dbo.v_StateMigration.SMPServerName, 
                          dbo.v_StateMigration.SourceMACAddresses, dbo.v_StateMigration.RestoreMACAddresses, dbo.StateMigration.StateEncryptDecryptKey, 
                          dbo.StateMigration.StorePath, dbo.StateMigration.StoreSize
    FROM         dbo.StateMigration INNER JOIN
                          dbo.v_StateMigration ON dbo.StateMigration.SMPServerName = dbo.v_StateMigration.SMPServerName CROSS JOIN
                          dbo.v_UserStateMigration
    WHERE     (dbo.StateMigration.StorePath IS NOT NULL) AND (dbo.StateMigration.StoreSize IS NOT NULL)
    ORDER BY dbo.v_StateMigration.SourceName

    Try this.
    SELECT Distinct
    SM.SourceName,
    SM.SiteCode,
    SM.SMPServerName,
    SM.SourceMACAddresses,
    SM.RestoreMACAddresses,
    SMT.StateEncryptDecryptKey,
    SM.StorePath,
    SM.StoreSize
    FROM
    dbo.v_StateMigration SM
    JOIN dbo.v_UserStateMigration UM on SM.RestoreClientResourceID= UM.RestoreClientResourceID
    join dbo.StateMigration SMT on SM.SMPServerName = SMT.SMPServerName
    WHERE
    (SM.StorePath IS NOT NULL)
    AND (SM.StoreSize IS NOT NULL)
    ORDER BY
    SM.SourceName
    http://www.enhansoft.com/

  • Open invoice customer ageing query

    I have set up a query to find a customer aging report - open ivoices. I just want to have open records... does anyone have a better query for this?
    SELECT     TOP (100) PERCENT dbo.OCRD.CardName, dbo.OCRD.Balance, (CASE WHEN DATEDIFF(DD, T0.REFDATE, GETDATE()) BETWEEN 0 AND
                          30 THEN CASE WHEN T1.SYSCred <> 0 THEN T1.SYSCred * - 1 ELSE T1.SYSDeb END ELSE 0 END) AS [0-30], (CASE WHEN DATEDIFF(DD, T0.REFDATE, GETDATE())
                          BETWEEN 31 AND 60 THEN CASE WHEN T1.SYSCred <> 0 THEN T1.SYSCred * - 1 ELSE T1.SYSDeb END ELSE 0 END) AS [31-60], (CASE WHEN DATEDIFF(DD,
                          T0.REFDATE, GETDATE()) BETWEEN 61 AND 90 THEN CASE WHEN T1.SYSCred <> 0 THEN T1.SYSCred * - 1 ELSE T1.SYSDeb END ELSE 0 END) AS [61-90],
                          (CASE WHEN DATEDIFF(DD, T0.REFDATE, GETDATE()) > 91 THEN CASE WHEN T1.SYSCred <> 0 THEN T1.SYSCred * - 1 ELSE T1.SYSDeb END ELSE 0 END) AS [90+],
                          dbo.OCRD.CardType, T1.TransType, T1.TransCode, T1.LineMemo, T1.BaseRef, dbo.OCRD.CardCode, T1.BalDueDeb
    FROM         dbo.OJDT AS T0 INNER JOIN
                          dbo.JDT1 AS T1 ON T1.TransId = T0.TransId INNER JOIN
                          dbo.OCRD ON dbo.OCRD.CardCode = T1.ShortName
    WHERE     (dbo.OCRD.Balance >= 1) AND (dbo.OCRD.CardType = 'C') AND (T1.BalDueDeb > 0)
    ORDER BY dbo.OCRD.CardName
    Regards,
    knut

    Knut,
    Try this:
    SELECT T2.CardName, T2.Balance,
    (CASE WHEN DATEDIFF(DD, T0.REFDATE, GETDATE()) BETWEEN 0 AND
    30 THEN CASE WHEN T1.SYSCred != 0 THEN -T1.SYSCred ELSE T1.SYSDeb END ELSE 0 END) AS '0-30',
    (CASE WHEN DATEDIFF(DD, T0.REFDATE, GETDATE()) BETWEEN 31 AND
    60 THEN CASE WHEN T1.SYSCred != 0 THEN -T1.SYSCred ELSE T1.SYSDeb END ELSE 0 END) AS '31-60',
    (CASE WHEN DATEDIFF(DD, T0.REFDATE, GETDATE()) BETWEEN 61 AND
    90 THEN CASE WHEN T1.SYSCred != 0 THEN -T1.SYSCred ELSE T1.SYSDeb END ELSE 0 END) AS '61-90',
    (CASE WHEN DATEDIFF(DD, T0.REFDATE, GETDATE()) >90
    THEN CASE WHEN T1.SYSCred != 0 THEN -T1.SYSCred ELSE T1.SYSDeb END ELSE 0 END) AS '90+',
    T1.TransType, T1.TransCode, T1.LineMemo, T1.BaseRef, T2.CardCode
    FROM dbo.OJDT T0
    INNER JOIN dbo.JDT1 T1 ON T1.TransId = T0.TransId
    INNER JOIN dbo.OCRD T2 ON T2.CardCode = T1.ShortName
    WHERE (T2.Balance >= 1) AND (T2.CardType = 'C') AND (T1.BalDueDeb != T1.BalDueCred)
    Thanks,
    Gordon

  • Crystal report related problem

    Hello All,
    SELECT
    TOP (100) PERCENT T0.CardCode, T0.CardName, T0.Address, T3.Name, T0.DocDate, T0.DocNum, T0.VatSumFC, T0.U_Suffix, T2.Phone1, T2.Phone2,
    T2.Fax, T4.PymntGroup, T1.Dscription, T1.ItemCode, T1.Quantity, T1.OpenQty, T1.Price, T1.Currency, T1.LineTotal, T1.TotalFrgn, T1.U_Text_Rate,
    T1.Quantity as U_Order_Qty, T1.OpenQty as U_Order_OpenQty, T6.InvntryUom,  T1.U_Order_UoM, T1.Price as U_List_Price, 1 as U_ConvFactor, T1.U_OB_MANU, T1.U_OB_MANUPART, T1.FreeTxt,
    T5.SlpName, T5.Memo, T0.U_RequestedBy, T0.U_Note1, T0.SlpCode, T0.U_Note2, T0.U_Remarks1, T0.U_Remarks2, T0.U_Remarks3,
    T0.U_Remarks4, T0.U_Remarks5, T0.U_Remarks6, T0.U_Remarks7, T0.U_Remarks8, T0.U_Remarks9, T0.U_Remarks10, T0.U_Remarks11,
    T0.U_Remarks12, T0.U_Remarks13, T0.U_Remarks14, T0.U_Remarks15, T0.U_Remarks16, T0.VatSum, T0.DocDueDate, T1.LinManClsd, T0.DiscPrcnt,
    T0.DiscSum, T0.DiscSumFC, T6.SWW, SUM(T7.Quantity) AS RecdOrdrQty, SUM(T7.Quantity) AS RecdQty, T1.LineNum, T1.VisOrder
    FROM    
    dbo.OPOR AS T0 INNER JOIN
    dbo.POR1 AS T1 ON T0.DocEntry = T1.DocEntry INNER JOIN
    dbo.OCRD AS T2 ON T0.CardCode = T2.CardCode INNER JOIN
    dbo.OCPR AS T3 ON T0.CntctCode = T3.CntctCode INNER JOIN
    dbo.OCTG AS T4 ON T0.GroupNum = T4.GroupNum INNER JOIN
    dbo.OSLP AS T5 ON T0.SlpCode = T5.SlpCode INNER JOIN
    dbo.OITM AS T6 ON T1.ItemCode = T6.ItemCode LEFT OUTER JOIN
    dbo.PDN1 AS T7 ON T1.DocEntry = T7.BaseEntry AND T1.LineNum = T7.BaseLine
    Where
        T0.DocEntry = {?Dockey@}
    GROUP BY T0.CardCode, T0.CardName, T0.Address, T3.Name, T0.DocDate, T0.DocNum, T0.VatSumFC, T0.U_Suffix, T2.Phone1, T2.Phone2, T2.Fax,
    T4.PymntGroup, T1.Dscription, T1.ItemCode, T1.Quantity, T1.OpenQty, T1.Price, T1.Currency, T1.LineTotal, T1.TotalFrgn, T1.U_Text_Rate,
    T1.Quantity, T1.OpenQty, T6.InvntryUom, T1.U_Order_UoM, T1.Price, T1.U_OB_MANU, T1.U_OB_MANUPART, T1.FreeTxt,
    T5.SlpName, T5.Memo, T0.U_RequestedBy, T0.U_Note1, T0.SlpCode, T0.U_Note2, T0.U_Remarks1, T0.U_Remarks2, T0.U_Remarks3,
    T0.U_Remarks4, T0.U_Remarks5, T0.U_Remarks6, T0.U_Remarks7, T0.U_Remarks8, T0.U_Remarks9, T0.U_Remarks10, T0.U_Remarks11,
    T0.U_Remarks12, T0.U_Remarks13, T0.U_Remarks14, T0.U_Remarks15, T0.U_Remarks16, T0.VatSum, T0.DocDueDate, T1.LinManClsd, T0.DiscPrcnt,
    T0.DiscSum, T0.DiscSumFC, T6.SWW, T1.LineNum, T1.VisOrder
    ORDER BY T1.VisOrder
    I have wrote above query in crystal reports. Its working fine
    But i am not able to see the Print Preview only for 2 business partners.
    Can anyone check this query and help me to find out the issue.
    Regards,
    Hitul

    HI , 
    This conditions may be problem for that particular BP , 
    dbo.OCPR AS T3 ON T0.CntctCode = T3.CntctCode INNER JOIN  
    dbo.OCTG AS T4 ON T0.GroupNum = T4.GroupNum INNER JOIN  
    you can Change LEFT JOIN instead of INNER JOIN and then check the result.
    -Rajesh N

  • SQL Query Performance Issue

    Hey,
    Please forgive me if I'm missing something really obvious but it's been a while since I did any SQL work and I'm obviously a bit rusty.
    When the below query is run the CPU on the SQL server maxes out. The query itself takes over 6 hours to run.
    Is there anything glaringly obvious with the query that might be causing thisCheers
    Paul
    SELECT TOP (100) PERCENT dbo.CUSTPACKINGSLIPTRANS.ITEMID AS [Stock Code],
    dbo.CUSTPACKINGSLIPTRANS.SALESUNIT AS [Unit of Sale],
    dbo.DIMENSIONFINANCIALTAG.DESCRIPTION AS [Product Group],
    dbo.INVENTITEMGROUP.ITEMGROUPID AS [Item Group],
    dbo.INVENTTABLE.SECTION,
    dbo.INVENTTABLE.GROUPS AS [Group],
    dbo.INVENTTABLE.SUBGROUPS AS [Sub Group],
    dbo.CUSTPACKINGSLIPJOUR.ORDERACCOUNT AS [Cust Account],
    dbo.CUSTTABLE.INVOICEACCOUNT AS [Invoice Account],
    dbo.DIRPARTYTABLE.NAME AS [Cust Name],
    dbo.CUSTTABLE.CURRENCY,
    dbo.CUSTTABLE.CIT_CONTROLLER AS [Credit Controller],
    dbo.CUSTTABLE.CREDITMAX AS [Credit Limit],
    dbo.CUSTTABLE.CUSTCLASSIFICATIONID AS Classification,
    dbo.DIRPERSONNAME.FIRSTNAME + ' ' + dbo.DIRPERSONNAME.LASTNAME AS [Sales Person],
    dbo.SALESTABLE.SALESGROUP AS [Outside Rooms],
    CASE WHEN CUSTTABLE.CUSTCLASSIFICATIONID = 'Cash' THEN dbo.SALESTABLE.SALESGROUP ELSE dbo.CUSTTABLE.SALESGROUP END AS [Sales Rep],
    dbo.LOGISTICSPOSTALADDRESS.STATE [Customer Region],
    dbo.LOGISTICSPOSTALADDRESS.COUNTY [Customer County],
    dbo.CUSTTABLE.LINEOFBUSINESSID AS [Line Of Business],
    a.DISPLAYVALUE AS [Site/Location],
    dbo.CUSTPACKINGSLIPTRANS.PACKINGSLIPID AS [Delivery Ref],
    dbo.LOGISTICSPOSTALADDRESS.COUNTRYREGIONID,
    CONVERT(varchar(12), dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE, 111) AS [Delivery Date],
    dbo.LOGISTICSPOSTALADDRESS.ADDRESS AS [Delivery Address],
    dbo.CUSTPACKINGSLIPTRANS.VALUEMST AS [Delivery Value (CON)],
    CONVERT(varchar(12), dbo.SALESTABLE.RECEIPTDATEREQUESTED, 111) AS [Requested Delivery Date],
    dbo.SALESTABLE.SALESID AS [Order Ref],
    CASE dbo.SALESTABLE.SALESSTATUS WHEN '0' THEN 'None' WHEN '1' THEN 'Open Order' WHEN '2' THEN 'Delivered' WHEN '3' THEN 'Invoiced' WHEN '4' THEN 'Canceled' END AS [Sales Status],
    CASE dbo.SALESTABLE.SALESTYPE WHEN '0' THEN 'Journal' WHEN '1' THEN 'Quotation' WHEN '2' THEN 'Subscription' WHEN '3' THEN 'Sales Order' WHEN '4' THEN 'Returned Item' WHEN '5' THEN 'Blanket Order' WHEN '6' THEN 'Item Requirements' WHEN '7' THEN 'Undefined' END AS [Sales Type],
    CASE dbo.SALESTABLE.AG_SALESLOCATION WHEN '0' THEN 'None' WHEN '1' THEN 'OR_DGN' WHEN '2' THEN 'OR_FMT' WHEN '3' THEN 'OR_TME' WHEN '4' THEN 'OR_OMA' WHEN '5' THEN 'DSP_DGN' WHEN '6' THEN 'DSP_FMT' WHEN '7' THEN 'DSP_TME' WHEN '8' THEN 'DSP_OMA' WHEN '9' THEN 'DSP_BEL' WHEN '10' THEN 'DSP_CDF' WHEN '11' THEN 'DSP_BGY' WHEN '12' THEN 'Credit Control' WHEN '13' THEN 'Internal Sales' WHEN '14' THEN 'CP_FMT' WHEN '15' THEN 'GBSales' END AS [Sales Location],
    dbo.SALESTABLE.PURCHORDERFORMNUM AS [Customer Requisition],
    dbo.SALESLINE.LINEDISC AS [Line Disc],
    dbo.SALESLINE.LINEPERCENT AS [Line Percent],
    dbo.SALESLINE.PRICEGROUPID AS [Price Group],
    dbo.INVENTDIM.INVENTLOCATIONID AS Warehouse,
    dbo.DIRPARTYTABLE.NAMEALIAS AS [Search Name],
    dbo.CUSTPACKINGSLIPJOUR.LORRYID AS [Lorry ID],
    dbo.CUSTPACKINGSLIPJOUR.LORRYREGNO AS [Lorry Reg],
    dbo.CUSTPACKINGSLIPJOUR.LORRYDRIVER AS [Lorry Driver],
    CASE dbo.SALESLINE.BLOCKED WHEN '0' THEN 'No' WHEN '1' THEN 'Yes' END AS [Stopped?],
    dbo.CUSTPACKINGSLIPTRANS.QTY AS [Qty Delivered],
    dbo.SALESLINE.SALESPRICE AS [Unit Price],
    dbo.CUSTPACKINGSLIPJOUR.CREATEDBY AS [SDN Creator],
    MONTH(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) AS Month,
    YEAR(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) AS Year,
    DATEPART(week, dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) AS WeekNo,
    CASE MONTH(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) WHEN '1' THEN '10' WHEN '2' THEN '11' WHEN '3' THEN '12' WHEN '4' THEN '1' WHEN '5' THEN '2' WHEN '6' THEN '3' WHEN '7' THEN '4' WHEN '8' THEN '5' WHEN '9' THEN '6' WHEN '10' THEN '7' WHEN '11' THEN '8' WHEN '12' THEN '9' END AS [Fin Period], CASE WHEN MONTH(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) <= '3' THEN CONVERT(VARCHAR(10), (YEAR(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) - 1)) + '/' + CONVERT(VARCHAR(10), YEAR(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE)) WHEN MONTH(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) >= '4' THEN CONVERT(VARCHAR(10), YEAR(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE)) + '/' + CONVERT(VARCHAR(10), (YEAR(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) + 1)) END AS [Fin Year],
    CASE WHEN dbo.custpackingsliptrans.salesunit = '100' THEN dbo.CUSTPACKINGSLIPTRANS.SALESUNIT * dbo.CUSTPACKINGSLIPTRANS.QTY WHEN dbo.custpackingsliptrans.salesunit = '1000' THEN dbo.CUSTPACKINGSLIPTRANS.SALESUNIT * dbo.CUSTPACKINGSLIPTRANS.QTY ELSE dbo.CUSTPACKINGSLIPTRANS.QTY END AS [No of Units],
    CASE dbo.INVENTITEMGROUPITEM.ITEMGROUPID WHEN 'Mortar' THEN (dbo.INVENTTABLE.NETWEIGHT * dbo.CUSTPACKINGSLIPTRANS.QTY) WHEN 'Sand' THEN (dbo.INVENTTABLE.NETWEIGHT * dbo.CUSTPACKINGSLIPTRANS.QTY) WHEN 'Decorative Gravel' THEN (dbo.INVENTTABLE.NETWEIGHT * dbo.CUSTPACKINGSLIPTRANS.QTY) WHEN 'Crushed Aggregates' THEN (dbo.INVENTTABLE.NETWEIGHT * dbo.CUSTPACKINGSLIPTRANS.QTY) WHEN 'Lintels' THEN (dbo.INVENTTABLE.NETWEIGHT * dbo.CUSTPACKINGSLIPTRANS.QTY) / 1000 WHEN 'TBeams' THEN (dbo.INVENTTABLE.NETWEIGHT * dbo.CUSTPACKINGSLIPTRANS.QTY) / 1000 WHEN 'Aggregates' THEN (dbo.INVENTTABLE.NETWEIGHT * dbo.CUSTPACKINGSLIPTRANS.QTY) WHEN 'Lime' THEN (dbo.INVENTTABLE.NETWEIGHT * dbo.CUSTPACKINGSLIPTRANS.QTY * dbo.UNITOFMEASURECONVERSION.FACTOR) WHEN 'Readymix' THEN (dbo.INVENTTABLE.NETWEIGHT * dbo.CUSTPACKINGSLIPTRANS.QTY) / 1000 ELSE (dbo.INVENTTABLE.NETWEIGHT * dbo.CUSTPACKINGSLIPTRANS.QTY * dbo.UNITOFMEASURECONVERSION.FACTOR) / 1000 END AS Tonnage,
    dbo.INVENTTABLE.NETWEIGHT AS [Net Weight],
    dbo.INVENTTABLE.PRODCOSTA,
    dbo.INVENTTABLE.PRODCOSTB,
    dbo.INVENTTABLE.PRODCOSTC,
    dbo.INVENTTABLE.PRODCOSTD,
    dbo.INVENTTABLE.PRODCOSTE,
    dbo.INVENTTABLE.PRODCOSTF,
    dbo.INVENTTABLE.PRODCOSTG,
    dbo.INVENTTABLE.PRODCOSTH,
    dbo.INVENTTABLE.QTYPERBALE,
    dbo.INVENTTABLE.M2PERBALE,
    dbo.SALESTABLE.SALESTYPE,
    dbo.SALESTABLE.DLVMODE AS [Delivery Mode],
    CONVERT(varchar(12), dbo.SALESTABLE.SHIPPINGDATECONFIRMED, 111) AS [Shipping Date Confirmed],
    CONVERT(varchar(12), dbo.SALESTABLE.CREATEDDATETIME, 111) AS [Created Date],
    dbo.SALESLINE.CUSTGROUP AS [Cust Group],
    dbo.INVENTTABLE.MADETOORDER AS [Made To Order]
    FROM dbo.CUSTPACKINGSLIPTRANS INNER JOIN
    dbo.CUSTPACKINGSLIPJOUR ON dbo.CUSTPACKINGSLIPTRANS.PACKINGSLIPID = dbo.CUSTPACKINGSLIPJOUR.PACKINGSLIPID INNER JOIN
    dbo.SALESLINE ON dbo.CUSTPACKINGSLIPJOUR.SALESID = dbo.SALESLINE.SALESID AND
    dbo.CUSTPACKINGSLIPTRANS.INVENTTRANSID = dbo.SALESLINE.INVENTTRANSID INNER JOIN
    dbo.INVENTTABLE ON dbo.CUSTPACKINGSLIPTRANS.ITEMID = dbo.INVENTTABLE.ITEMID INNER JOIN
    dbo.INVENTITEMGROUPITEM ON dbo.INVENTTABLE.ITEMID = dbo.INVENTITEMGROUPITEM.ITEMID INNER JOIN
    dbo.INVENTITEMGROUP ON dbo.INVENTITEMGROUPITEM.ITEMGROUPID = dbo.INVENTITEMGROUP.ITEMGROUPID INNER JOIN
    dbo.INVENTDIM ON dbo.SALESLINE.INVENTDIMID = dbo.INVENTDIM.INVENTDIMID INNER JOIN
    dbo.CUSTTABLE ON dbo.CUSTPACKINGSLIPJOUR.ORDERACCOUNT = dbo.CUSTTABLE.ACCOUNTNUM INNER JOIN
    dbo.DIRPARTYTABLE ON dbo.CUSTTABLE.PARTY = dbo.DIRPARTYTABLE.RECID INNER JOIN
    dbo.LOGISTICSPOSTALADDRESS ON dbo.DIRPARTYTABLE.PRIMARYADDRESSLOCATION = dbo.LOGISTICSPOSTALADDRESS.LOCATION INNER JOIN
    dbo.SALESTABLE ON dbo.SALESLINE.SALESID = dbo.SALESTABLE.SALESID INNER JOIN
    dbo.DIRPERSONNAME ON dbo.SALESTABLE.WORKERSALESTAKER = dbo.DIRPERSONNAME.RECID INNER JOIN
    dbo.ECORESPRODUCT ON dbo.CUSTPACKINGSLIPTRANS.ITEMID = dbo.ECORESPRODUCT.SEARCHNAME
    AND dbo.INVENTTABLE.ITEMID = dbo.ECORESPRODUCT.DISPLAYPRODUCTNUMBER LEFT OUTER JOIN
    dbo.UNITOFMEASURECONVERSION ON dbo.ECORESPRODUCT.RECID = dbo.UNITOFMEASURECONVERSION.PRODUCT LEFT OUTER JOIN
    dbo.UNITOFMEASURE ON dbo.UNITOFMEASURECONVERSION.TOUNITOFMEASURE = dbo.UNITOFMEASURE.RECID INNER JOIN
    dbo.DEFAULTDIMENSIONVIEW a ON dbo.CUSTPACKINGSLIPTRANS.DEFAULTDIMENSION = a.DEFAULTDIMENSION AND a.NAME = 'Department' LEFT OUTER JOIN
    dbo.DEFAULTDIMENSIONVIEW b ON dbo.INVENTTABLE.DEFAULTDIMENSION = b.DEFAULTDIMENSION AND b.NAME = 'Center' INNER JOIN
    dbo.DIMENSIONFINANCIALTAG ON b.ENTITYINSTANCE = dbo.DIMENSIONFINANCIALTAG.RECID
    WHERE (dbo.CUSTPACKINGSLIPTRANS.DATAAREAID = 'agl') AND
    (dbo.CUSTPACKINGSLIPJOUR.DATAAREAID = 'agl') AND
    (dbo.SALESLINE.DATAAREAID = 'agl') AND
    (dbo.INVENTTABLE.DATAAREAID = 'vuk') AND
    (dbo.INVENTDIM.DATAAREAID = 'agl') AND
    (dbo.CUSTTABLE.DATAAREAID = 'agl') AND
    (dbo.SALESTABLE.DATAAREAID = 'agl') AND
    (CASE WHEN MONTH(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) <= '3' THEN (YEAR(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) - 1)
    WHEN MONTH(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) >= '4' THEN YEAR(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) END = 2014)

    Hey,
    Please forgive me if I'm missing something really obvious but it's been a while since I did any SQL work and I'm obviously a bit rusty.
    When the below query is run the CPU on the SQL server maxes out. The query itself takes over 6 hours to run.
    Is there anything glaringly obvious with the query that might be causing thisCheers
    Paul
    SELECT TOP (100) PERCENT dbo.CUSTPACKINGSLIPTRANS.ITEMID AS [Stock Code],
    dbo.CUSTPACKINGSLIPTRANS.SALESUNIT AS [Unit of Sale],
    dbo.DIMENSIONFINANCIALTAG.DESCRIPTION AS [Product Group],
    dbo.INVENTITEMGROUP.ITEMGROUPID AS [Item Group],
    dbo.INVENTTABLE.SECTION,
    dbo.INVENTTABLE.GROUPS AS [Group],
    dbo.INVENTTABLE.SUBGROUPS AS [Sub Group],
    dbo.CUSTPACKINGSLIPJOUR.ORDERACCOUNT AS [Cust Account],
    dbo.CUSTTABLE.INVOICEACCOUNT AS [Invoice Account],
    dbo.DIRPARTYTABLE.NAME AS [Cust Name],
    dbo.CUSTTABLE.CURRENCY,
    dbo.CUSTTABLE.CIT_CONTROLLER AS [Credit Controller],
    dbo.CUSTTABLE.CREDITMAX AS [Credit Limit],
    dbo.CUSTTABLE.CUSTCLASSIFICATIONID AS Classification,
    dbo.DIRPERSONNAME.FIRSTNAME + ' ' + dbo.DIRPERSONNAME.LASTNAME AS [Sales Person],
    dbo.SALESTABLE.SALESGROUP AS [Outside Rooms],
    CASE WHEN CUSTTABLE.CUSTCLASSIFICATIONID = 'Cash' THEN dbo.SALESTABLE.SALESGROUP ELSE dbo.CUSTTABLE.SALESGROUP END AS [Sales Rep],
    dbo.LOGISTICSPOSTALADDRESS.STATE [Customer Region],
    dbo.LOGISTICSPOSTALADDRESS.COUNTY [Customer County],
    dbo.CUSTTABLE.LINEOFBUSINESSID AS [Line Of Business],
    a.DISPLAYVALUE AS [Site/Location],
    dbo.CUSTPACKINGSLIPTRANS.PACKINGSLIPID AS [Delivery Ref],
    dbo.LOGISTICSPOSTALADDRESS.COUNTRYREGIONID,
    CONVERT(varchar(12), dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE, 111) AS [Delivery Date],
    dbo.LOGISTICSPOSTALADDRESS.ADDRESS AS [Delivery Address],
    dbo.CUSTPACKINGSLIPTRANS.VALUEMST AS [Delivery Value (CON)],
    CONVERT(varchar(12), dbo.SALESTABLE.RECEIPTDATEREQUESTED, 111) AS [Requested Delivery Date],
    dbo.SALESTABLE.SALESID AS [Order Ref],
    CASE dbo.SALESTABLE.SALESSTATUS WHEN '0' THEN 'None' WHEN '1' THEN 'Open Order' WHEN '2' THEN 'Delivered' WHEN '3' THEN 'Invoiced' WHEN '4' THEN 'Canceled' END AS [Sales Status],
    CASE dbo.SALESTABLE.SALESTYPE WHEN '0' THEN 'Journal' WHEN '1' THEN 'Quotation' WHEN '2' THEN 'Subscription' WHEN '3' THEN 'Sales Order' WHEN '4' THEN 'Returned Item' WHEN '5' THEN 'Blanket Order' WHEN '6' THEN 'Item Requirements' WHEN '7' THEN 'Undefined' END AS [Sales Type],
    CASE dbo.SALESTABLE.AG_SALESLOCATION WHEN '0' THEN 'None' WHEN '1' THEN 'OR_DGN' WHEN '2' THEN 'OR_FMT' WHEN '3' THEN 'OR_TME' WHEN '4' THEN 'OR_OMA' WHEN '5' THEN 'DSP_DGN' WHEN '6' THEN 'DSP_FMT' WHEN '7' THEN 'DSP_TME' WHEN '8' THEN 'DSP_OMA' WHEN '9' THEN 'DSP_BEL' WHEN '10' THEN 'DSP_CDF' WHEN '11' THEN 'DSP_BGY' WHEN '12' THEN 'Credit Control' WHEN '13' THEN 'Internal Sales' WHEN '14' THEN 'CP_FMT' WHEN '15' THEN 'GBSales' END AS [Sales Location],
    dbo.SALESTABLE.PURCHORDERFORMNUM AS [Customer Requisition],
    dbo.SALESLINE.LINEDISC AS [Line Disc],
    dbo.SALESLINE.LINEPERCENT AS [Line Percent],
    dbo.SALESLINE.PRICEGROUPID AS [Price Group],
    dbo.INVENTDIM.INVENTLOCATIONID AS Warehouse,
    dbo.DIRPARTYTABLE.NAMEALIAS AS [Search Name],
    dbo.CUSTPACKINGSLIPJOUR.LORRYID AS [Lorry ID],
    dbo.CUSTPACKINGSLIPJOUR.LORRYREGNO AS [Lorry Reg],
    dbo.CUSTPACKINGSLIPJOUR.LORRYDRIVER AS [Lorry Driver],
    CASE dbo.SALESLINE.BLOCKED WHEN '0' THEN 'No' WHEN '1' THEN 'Yes' END AS [Stopped?],
    dbo.CUSTPACKINGSLIPTRANS.QTY AS [Qty Delivered],
    dbo.SALESLINE.SALESPRICE AS [Unit Price],
    dbo.CUSTPACKINGSLIPJOUR.CREATEDBY AS [SDN Creator],
    MONTH(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) AS Month,
    YEAR(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) AS Year,
    DATEPART(week, dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) AS WeekNo,
    CASE MONTH(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) WHEN '1' THEN '10' WHEN '2' THEN '11' WHEN '3' THEN '12' WHEN '4' THEN '1' WHEN '5' THEN '2' WHEN '6' THEN '3' WHEN '7' THEN '4' WHEN '8' THEN '5' WHEN '9' THEN '6' WHEN '10' THEN '7' WHEN '11' THEN '8' WHEN '12' THEN '9' END AS [Fin Period], CASE WHEN MONTH(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) <= '3' THEN CONVERT(VARCHAR(10), (YEAR(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) - 1)) + '/' + CONVERT(VARCHAR(10), YEAR(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE)) WHEN MONTH(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) >= '4' THEN CONVERT(VARCHAR(10), YEAR(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE)) + '/' + CONVERT(VARCHAR(10), (YEAR(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) + 1)) END AS [Fin Year],
    CASE WHEN dbo.custpackingsliptrans.salesunit = '100' THEN dbo.CUSTPACKINGSLIPTRANS.SALESUNIT * dbo.CUSTPACKINGSLIPTRANS.QTY WHEN dbo.custpackingsliptrans.salesunit = '1000' THEN dbo.CUSTPACKINGSLIPTRANS.SALESUNIT * dbo.CUSTPACKINGSLIPTRANS.QTY ELSE dbo.CUSTPACKINGSLIPTRANS.QTY END AS [No of Units],
    CASE dbo.INVENTITEMGROUPITEM.ITEMGROUPID WHEN 'Mortar' THEN (dbo.INVENTTABLE.NETWEIGHT * dbo.CUSTPACKINGSLIPTRANS.QTY) WHEN 'Sand' THEN (dbo.INVENTTABLE.NETWEIGHT * dbo.CUSTPACKINGSLIPTRANS.QTY) WHEN 'Decorative Gravel' THEN (dbo.INVENTTABLE.NETWEIGHT * dbo.CUSTPACKINGSLIPTRANS.QTY) WHEN 'Crushed Aggregates' THEN (dbo.INVENTTABLE.NETWEIGHT * dbo.CUSTPACKINGSLIPTRANS.QTY) WHEN 'Lintels' THEN (dbo.INVENTTABLE.NETWEIGHT * dbo.CUSTPACKINGSLIPTRANS.QTY) / 1000 WHEN 'TBeams' THEN (dbo.INVENTTABLE.NETWEIGHT * dbo.CUSTPACKINGSLIPTRANS.QTY) / 1000 WHEN 'Aggregates' THEN (dbo.INVENTTABLE.NETWEIGHT * dbo.CUSTPACKINGSLIPTRANS.QTY) WHEN 'Lime' THEN (dbo.INVENTTABLE.NETWEIGHT * dbo.CUSTPACKINGSLIPTRANS.QTY * dbo.UNITOFMEASURECONVERSION.FACTOR) WHEN 'Readymix' THEN (dbo.INVENTTABLE.NETWEIGHT * dbo.CUSTPACKINGSLIPTRANS.QTY) / 1000 ELSE (dbo.INVENTTABLE.NETWEIGHT * dbo.CUSTPACKINGSLIPTRANS.QTY * dbo.UNITOFMEASURECONVERSION.FACTOR) / 1000 END AS Tonnage,
    dbo.INVENTTABLE.NETWEIGHT AS [Net Weight],
    dbo.INVENTTABLE.PRODCOSTA,
    dbo.INVENTTABLE.PRODCOSTB,
    dbo.INVENTTABLE.PRODCOSTC,
    dbo.INVENTTABLE.PRODCOSTD,
    dbo.INVENTTABLE.PRODCOSTE,
    dbo.INVENTTABLE.PRODCOSTF,
    dbo.INVENTTABLE.PRODCOSTG,
    dbo.INVENTTABLE.PRODCOSTH,
    dbo.INVENTTABLE.QTYPERBALE,
    dbo.INVENTTABLE.M2PERBALE,
    dbo.SALESTABLE.SALESTYPE,
    dbo.SALESTABLE.DLVMODE AS [Delivery Mode],
    CONVERT(varchar(12), dbo.SALESTABLE.SHIPPINGDATECONFIRMED, 111) AS [Shipping Date Confirmed],
    CONVERT(varchar(12), dbo.SALESTABLE.CREATEDDATETIME, 111) AS [Created Date],
    dbo.SALESLINE.CUSTGROUP AS [Cust Group],
    dbo.INVENTTABLE.MADETOORDER AS [Made To Order]
    FROM dbo.CUSTPACKINGSLIPTRANS INNER JOIN
    dbo.CUSTPACKINGSLIPJOUR ON dbo.CUSTPACKINGSLIPTRANS.PACKINGSLIPID = dbo.CUSTPACKINGSLIPJOUR.PACKINGSLIPID INNER JOIN
    dbo.SALESLINE ON dbo.CUSTPACKINGSLIPJOUR.SALESID = dbo.SALESLINE.SALESID AND
    dbo.CUSTPACKINGSLIPTRANS.INVENTTRANSID = dbo.SALESLINE.INVENTTRANSID INNER JOIN
    dbo.INVENTTABLE ON dbo.CUSTPACKINGSLIPTRANS.ITEMID = dbo.INVENTTABLE.ITEMID INNER JOIN
    dbo.INVENTITEMGROUPITEM ON dbo.INVENTTABLE.ITEMID = dbo.INVENTITEMGROUPITEM.ITEMID INNER JOIN
    dbo.INVENTITEMGROUP ON dbo.INVENTITEMGROUPITEM.ITEMGROUPID = dbo.INVENTITEMGROUP.ITEMGROUPID INNER JOIN
    dbo.INVENTDIM ON dbo.SALESLINE.INVENTDIMID = dbo.INVENTDIM.INVENTDIMID INNER JOIN
    dbo.CUSTTABLE ON dbo.CUSTPACKINGSLIPJOUR.ORDERACCOUNT = dbo.CUSTTABLE.ACCOUNTNUM INNER JOIN
    dbo.DIRPARTYTABLE ON dbo.CUSTTABLE.PARTY = dbo.DIRPARTYTABLE.RECID INNER JOIN
    dbo.LOGISTICSPOSTALADDRESS ON dbo.DIRPARTYTABLE.PRIMARYADDRESSLOCATION = dbo.LOGISTICSPOSTALADDRESS.LOCATION INNER JOIN
    dbo.SALESTABLE ON dbo.SALESLINE.SALESID = dbo.SALESTABLE.SALESID INNER JOIN
    dbo.DIRPERSONNAME ON dbo.SALESTABLE.WORKERSALESTAKER = dbo.DIRPERSONNAME.RECID INNER JOIN
    dbo.ECORESPRODUCT ON dbo.CUSTPACKINGSLIPTRANS.ITEMID = dbo.ECORESPRODUCT.SEARCHNAME
    AND dbo.INVENTTABLE.ITEMID = dbo.ECORESPRODUCT.DISPLAYPRODUCTNUMBER LEFT OUTER JOIN
    dbo.UNITOFMEASURECONVERSION ON dbo.ECORESPRODUCT.RECID = dbo.UNITOFMEASURECONVERSION.PRODUCT LEFT OUTER JOIN
    dbo.UNITOFMEASURE ON dbo.UNITOFMEASURECONVERSION.TOUNITOFMEASURE = dbo.UNITOFMEASURE.RECID INNER JOIN
    dbo.DEFAULTDIMENSIONVIEW a ON dbo.CUSTPACKINGSLIPTRANS.DEFAULTDIMENSION = a.DEFAULTDIMENSION AND a.NAME = 'Department' LEFT OUTER JOIN
    dbo.DEFAULTDIMENSIONVIEW b ON dbo.INVENTTABLE.DEFAULTDIMENSION = b.DEFAULTDIMENSION AND b.NAME = 'Center' INNER JOIN
    dbo.DIMENSIONFINANCIALTAG ON b.ENTITYINSTANCE = dbo.DIMENSIONFINANCIALTAG.RECID
    WHERE (dbo.CUSTPACKINGSLIPTRANS.DATAAREAID = 'agl') AND
    (dbo.CUSTPACKINGSLIPJOUR.DATAAREAID = 'agl') AND
    (dbo.SALESLINE.DATAAREAID = 'agl') AND
    (dbo.INVENTTABLE.DATAAREAID = 'vuk') AND
    (dbo.INVENTDIM.DATAAREAID = 'agl') AND
    (dbo.CUSTTABLE.DATAAREAID = 'agl') AND
    (dbo.SALESTABLE.DATAAREAID = 'agl') AND
    (CASE WHEN MONTH(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) <= '3' THEN (YEAR(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) - 1)
    WHEN MONTH(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) >= '4' THEN YEAR(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) END = 2014)
    Try to minimize joins using intermediary tables, also you can consider limiting data based on date ranges and codes (DATAAREAID) before joining with other tables.

  • Report Based on SQL view not pulling in all parameters

    Post Author: ronhawker
    CA Forum: .NET
    I based a report on a SQL view below:SELECT     TOP (100) PERCENT CorpDirectory.Position, CorpDirectory.PhoneDirect, CorpDirectory.Email, CorpDirectory.Store, CorpDirectory.Name,                       CorpDirectory.PhoneFaxWave, CorpDirectory.Department, Store.StoreName, Store.StoreStreetAddress, Store.StoreCity, Store.StoreState,                       Store.StoreZip, Store.StorePhone, CorpDirectory.DisplayOrderFROM         dbo.CorpDirectory AS CorpDirectory INNER JOIN                      dbo.Store AS Store ON CorpDirectory.Store = Store.StoreORDER BY CorpDirectory.Store, CorpDirectory.Department, CorpDirectory.DisplayOrder, CorpDirectory.Name When the report was created the order by sequence only brought in the first parameter of CorpDirectory.Store. It seemed to ignore the other three order by parameters. I am running 10.2 is VS2005.

    Sharmila,
    Thanks for your response. Maybe I wasn't clear enough in my previous statement. I will give an example of what I am trying to accomplish.
    Let's say I have 2 date fields(SUBMITDATE,COMPLETEDATE) in a table TABLE A
    I want to calculate a field called CYCLETIME with the following conditions:
    If COMPLTEDATE is NULL, then CYCLETIME = SYSDATE-SUBMITDATE
    IF COMPLTEEDATE is not null, then CYCLETIME = COMPLTEEDATE-SUBMITDATE
    Would appreciate any help.
    Thanks
    Dev
    Hi,
    You can do the calculation in the sql query itself. Here is an example which shows the sum of salaray for each department in the scott.emp table.
    select deptno,sum(sal) sal
    from scott.emp
    group by deptno
    Thanks,
    Sharmila

  • Report for OS Architecture

    Anybody feel like creating a report for me in SCCM? :)  I am clueless when it comes to SQL Report Builder. I need a report that shows OS Architecture (32 bit or 64 bit). I have found some links out there already with a few people who have done this
    but they don't seem to have everything we need. Basically, I need the canned "Hardware 01A - Summary of computers in a specific collection" report slightly modified to also show the OS Architecture.
    EDIT: I guess all I really need to know is what table or view this OS Architecture data resides in within SQL? I have a few in-house developers who would be able to assist me, but it's a matter of us knowing where the architecture data resides in so we can
    join it.

    Thanks again for all the help. We got it figured out. I pretty much used skywalker's code but had to modify it ever so slightly as it did not like one line of code. So I changed it out with Benoit's suggestion and it works great! I did end up hard coding
    the Collection ID in the code below 'SMS00001'.
    SELECT DISTINCT
                             TOP (100) PERCENT dbo.v_R_System_Valid.ResourceID, dbo.v_R_System_Valid.Netbios_Name0 AS [Computer Name], dbo.v_R_System_Valid.Resource_Domain_OR_Workgr0
    AS [Domain/Workgroup],
                             dbo.v_Site.SiteName AS [SMS Site Name], CASE WHEN (dbo.v_GS_SYSTEM_CONSOLE_USAGE_MAXGROUP.TopConsoleUser0 IS NULL
    OR
                             dbo.v_GS_SYSTEM_CONSOLE_USAGE_MAXGROUP.TopConsoleUser0 = '-1') THEN 'Unknown' ELSE dbo.v_GS_SYSTEM_CONSOLE_USAGE_MAXGROUP.TopConsoleUser0
    END AS [Top Console User],
                             dbo.v_GS_OPERATING_SYSTEM.Caption0 AS [Operating System], dbo.v_GS_OPERATING_SYSTEM.CSDVersion0 AS [Service Pack
    Level], dbo.v_GS_PC_BIOS.SerialNumber0 AS [Serial Number],
                             dbo.v_GS_SYSTEM_ENCLOSURE_UNIQUE.SMBIOSAssetTag0 AS [Asset Tag], dbo.v_GS_COMPUTER_SYSTEM.Manufacturer0 AS Manufacturer,
    dbo.v_GS_COMPUTER_SYSTEM.Model0 AS Model,
                             dbo.v_GS_X86_PC_MEMORY.TotalPhysicalMemory0 AS [Memory (KBytes)], dbo.v_GS_PROCESSOR.Manufacturer0 AS [Processor
    Manufacturer], dbo.v_GS_PROCESSOR.Name0 AS [Processor Name],
                             dbo.v_GS_PROCESSOR.NormSpeed0 AS [Processor (GHz)],
                                 (SELECT        SUM(dbo.v_GS_LOGICAL_DISK.Size0) AS Expr1
                                   FROM            dbo.v_GS_LOGICAL_DISK
    INNER JOIN
    dbo.v_FullCollectionMembership ON dbo.v_FullCollectionMembership.ResourceID = dbo.v_GS_LOGICAL_DISK.ResourceID
                                   WHERE        (dbo.v_GS_LOGICAL_DISK.ResourceID
    = dbo.v_R_System_Valid.ResourceID) AND (dbo.v_FullCollectionMembership.CollectionID = 'SMS00001')) AS [Disk Space (MB)],
                                 (SELECT        SUM(v_GS_LOGICAL_DISK_2.FreeSpace0) AS
    Expr1
                                   FROM            dbo.v_GS_LOGICAL_DISK
    AS v_GS_LOGICAL_DISK_2 INNER JOIN
    dbo.v_FullCollectionMembership AS v_FullCollectionMembership_2 ON v_FullCollectionMembership_2.ResourceID = v_GS_LOGICAL_DISK_2.ResourceID
                                   WHERE        (v_GS_LOGICAL_DISK_2.ResourceID
    = dbo.v_R_System_Valid.ResourceID) AND (v_FullCollectionMembership_2.CollectionID = 'SMS00001')) AS [Free Disk Space (MB)],
                             dbo.v_GS_Computer_SYSTEM.SystemType0
    FROM            dbo.v_R_System_Valid INNER JOIN
                             dbo.v_GS_OPERATING_SYSTEM ON dbo.v_GS_OPERATING_SYSTEM.ResourceID = dbo.v_R_System_Valid.ResourceID LEFT OUTER JOIN
                             dbo.v_GS_SYSTEM_ENCLOSURE_UNIQUE ON dbo.v_GS_SYSTEM_ENCLOSURE_UNIQUE.ResourceID = dbo.v_R_System_Valid.ResourceID
    INNER JOIN
                             dbo.v_GS_COMPUTER_SYSTEM ON dbo.v_GS_COMPUTER_SYSTEM.ResourceID = dbo.v_R_System_Valid.ResourceID INNER JOIN
                             dbo.v_GS_X86_PC_MEMORY ON dbo.v_GS_X86_PC_MEMORY.ResourceID = dbo.v_R_System_Valid.ResourceID INNER JOIN
                             dbo.v_GS_PROCESSOR ON dbo.v_GS_PROCESSOR.ResourceID = dbo.v_R_System_Valid.ResourceID INNER JOIN
                             dbo.v_GS_PC_BIOS ON dbo.v_GS_PC_BIOS.ResourceID = dbo.v_R_System_Valid.ResourceID INNER JOIN
                             dbo.v_FullCollectionMembership AS v_FullCollectionMembership_1 ON v_FullCollectionMembership_1.ResourceID = dbo.v_R_System_Valid.ResourceID
    LEFT OUTER JOIN
                             dbo.v_Site ON v_FullCollectionMembership_1.SiteCode = dbo.v_Site.SiteCode INNER JOIN
                             dbo.v_GS_LOGICAL_DISK AS v_GS_LOGICAL_DISK_1 ON v_GS_LOGICAL_DISK_1.ResourceID = dbo.v_R_System_Valid.ResourceID
    AND
                             v_GS_LOGICAL_DISK_1.DeviceID0 = SUBSTRING(dbo.v_GS_OPERATING_SYSTEM.WindowsDirectory0, 1, 2) LEFT OUTER JOIN
                             dbo.v_GS_SYSTEM_CONSOLE_USAGE_MAXGROUP ON dbo.v_GS_SYSTEM_CONSOLE_USAGE_MAXGROUP.ResourceID = dbo.v_R_System_Valid.ResourceID
    WHERE        (v_FullCollectionMembership_1.CollectionID = 'SMS00001')
    ORDER BY [Computer Name]

  • What is your Review of the 928

    A User Review on the Nokia Lumia 928.
    Got my Nokia 928 a few days ago. First, overall the phone is GREAT and I would recommend it to anyone. IMO it is the Best Windows Phone to date. I will also say that in comparison to the other Operating System’s; Android and iOS, Windows Phone 8 OS is better and faster in my opinion. Of course that is Subjective. Everyone has his or her preference as to the features, apps, size, style, color and specs of a phone that work for them and that’s just fine. My sister likes the iphone 5 and it works just fine for here. My younger brother likes Android ICS and it works fine for him. The point is, I nor anyone else has to convince each person that they should buy a particular Phone. Having said that this is just a review for anyone not sure of Windows Phone 8.
    The Pros and the Cons.
    Pros:
    1.      The Operating System: The Windows Phone 8 OS is
    smooth fast and responsive. It runs faster on a lower processor than a newer Android’s faster quad processor. The point is, it doesn’t have to have 4 or more processors to run smoother and faster. Though I have not had it longer the 8 days as of this review I nor the persons I know who have a WP8, have not experienced the lags, bugs and many reboots I have had with Android Phones and Tablets.  I didn’t like the Windows Tiles when I first heard or seen them in pictures, but expect for the plain colors (you eventually get use to them) they work great. The Live Tiles update you on all the info you need on one screen without having to click on a bunch of different apps Mail, Facebook, Weather, Agenda, Calender, Messaging are all updated right on the front screen. You can customize the look, size, color of your Tiles and change them with ease.
    2.      The Camera: This has to be one of the best cameras on a Phone. You will not be disappoint on the pictures it takes in daylight or low light. Nokia is hyping up this Camera and I have to agree. The Camera alone is a good reason to get this phone.
    3.       Call Quality is good: Both calling and receiving. The speaker on it is loud and clear.
    4.      The Display is great with the AMOLED Display. It makes the screen sharp and clear and great even it sunlight. The Size at 4.5 inches is also a nice size, not too big and not too small.
    5.      Xenon Flash: Brighter and better Flash as found on some standalone cameras.
    6.      HD 1080p recording with great noise canceling mics. Also has front Facing 1.2MP camera.
    7.      32 GB internal storage
    8.      4G Network: I haven’t had the chance to fully test it yet, but my pages load super-fast and my downloads are fast as well.
    9.      Battery: Battery usage for a smartphone is Good. It also has wireless charging.
    10.   APPS: There is a lot of criticism with this OS and lack of apps. This area is where people have to put things in the right
    prospective. Yes iOS and Android has more Apps than WP8. I have to laugh a little when this argument is brought up. First who downloads that many apps? Second putting thing in the right prospective, iOS and Android is 5years old. Developers have had plenty of time to make apps. Windows Phone is going on 3years old with Window Phone 8 being only 6 months old with over 145,000 to date. Most of the top apps or equivalent is available right now on the WP store, with more being added as the months go buy. The point is, it took both Android and Apple years to get to the app count they have now. Besides most of the apps on those system or useless apps that don’t say on a phone for long yet alone even make it to ones phone. Again my point is most of the main or equivalent apps that people use are either on the store or in development. If Windows Phone 8 sells great(and I think it will) more apps will come faster. Anyway Nokia has a set of apps that make this phone stand out itself, Nokia Music, Nokia City Lens: Nokia Maps, Nokia Drive. There are plenty of other apps that make this a great pick.
    Cons:
    1.      No External Storage. I think Nokia made a mistake here. Even though it has an internal 32 gig storage( 23G usable) they should have made room for external storage. I like having my music, videos and some data on a storage card so I am not tied to a computer or downloading data on a cell or wifi. I almost didn’t get the phone because if this.
    2.      No removable battery. I am a heavy user, both personal and work. I like having a couple of charged batteries to throw in when I just can’t charge.
    3.      Lack of Apps? I put this here because in comparison to the other two OS’s, WP8 does have less apps, however I think I make a good point above as to why this is not a good reason to not buy this Phone.
    4.      No FM Radio: other Nokia Phones have the radio turned on. Though I heard that it can be turned on in a firmware update.
    5.      No Etiquette: My own personal preference; a feature that mutes the phone when you face it down.
    6.      Wish it had a stylus for notes: My own personal preference
    7.      No Swype Keyboard: My own personal preference
    8.      Unless I am wrong, No Video output to TV.
    Ok so for what it is worth, this is just an opinion for a user and not a article writer, and Yes I have had both Android and Iphone.

    Reviews? (not saying yours is one of em). YELP just announced some big  lawsuits vs groups posting glowing product reviews on their web site.  YELP isn't the only one with that issue On this site Ive seen glowing   post on top of glowing post for a phone that's still in pre order stage  unless you can get one in a store; verbage same review after review,I mention that because I relied on those  reviews to buy the 928 from another site and I'm satisfied those reviews  were pure fiction. Phone hadn't even been out very long, page after page of  glowing reviews
    I'm glad its working out for you That phone takes great photos . The rest is all marketing. What apps? Downloaded Mapquest's 4 star rated "voice activated, turn by turn" nav app that adjusts with drivers route. Does none of those things. Got lost 30 miles waiting for it to do so. 2 emails to Maquest "customer service" went unanswered You'll never see a company like Mapquest "marketing" apps that way on Google play or Apple store, no way. Those 170,000 windows store apps are just another page out of the MS "marketing" playbook. Go to a windows mobile forum and look under bugs and defects tab for the 928; page after page of battery life, audio,text, random freezes,update, storage issue for a Lumia phone that owns a 5% share of the total windows mobile market share which stands at bout 3%????? When I had either a nav or music app on I was getting 11% battery drainage rates per 19 minutes. Guess it all depends what you call power user. And I wasn't the only one with that issue.Phone is marketed as 17 hrs continuous usage and 24 standby on one charge. Yeah if you make a few phone calls and take some photos. I returned my 928 2 factory resets, bottomless pit of soft ones and one failed back up later, that phone is all marketing.
    PS. Vz's  much awaited flagship 928 windows phone came out in mid may. By mid august "flagship" was selling for free with 2 yr. All marketing. WP8 and I used it for 30 days is one BUGGY platform and that's not an opinion

  • How to specifically sort the data in a database using c#?

    H!,
    I have a problem in c# that require sorting of names of students in a sql database and i want it to be specific, i used data grid view to view the data of the students as shown below:
    Students First Name:
    Ann
    Antoinette
    Brenda
    Judith
    Lester
    Santos
    Suzie
    Tim
    if i type in a letter or abbreviation @ a textbox1 for example "s", all Names that starts with letter s will be sorted first so the output now of the query will become:
    Students First Name:
    Santos
    Suzie
    Ann
    Antoinette
    Brenda
    Judith
    Lester
    Tim
    So if i type j, all that starts with j will be first, and so on.
    I need help for this problem coz it is so hard for me to output the students with this kind of sorting and is there a code or query string related to this problem?
    thanks in advance.
    Hardz

    Hi,
    One way is to write a query as shown below:
    declare @char nvarchar(1)
    select @char = 'S'
    Declare @t table(name nvarchar(max))
    insert into @t
    values
    ('Santos'),
    ('Suzie'),
    ('Ann'),
    ('Antoinette'),
    ('Brenda'),
    ('Judith'),
    ('Lester'),
    ('Tim')
    select name
    from @t
    where RIGHT(name,1) like @char
    union all
    select name
    from
    (select top 100 percent name
    from @t
    where RIGHT(name,1) not like @char
    order by name) a
    Hope this helps. 
    -Chintak

  • SELECT * FROM table WHERE id NOT IN?  Help with statement.

    Hi,
    Two tables. Orders (orderID = PK) and Paid Orders (orderID =
    FK)
    I want to display a recordset of orders from the Orders table
    where the
    order ID doesn't appear in the Paid Orders table.
    I have tried something like this:
    SELECT *
    FROM dbo.tblOrders
    WHERE orderID NOT IN ( SELECT TOP 100 PERCENT
    tblPaidOrders.orderID FROM
    dbo.tblPaidOrders )
    ...no joy with that though. Would appreciate some guidance.
    Thank you.
    Regards
    Nath.

    Hi Nancy,
    Before I begin that, can I ask if there is an issue with the
    OR?
    I need it to be:
    (orderID IN (SELECT qryPaidOrders.orderID FROM qryPaidOrders)
    ORDER BY
    orderdate ASC) AND ((customerid = MMColParam1) OR (vanopID =
    MMColParam2))
    MMColParam1 is exactly the same as MMColParam but, for some
    reason
    unbeknowns to me, DW8.0.2 won't allow me to use it twice.
    That's neither
    here nor there though, as creating a 2nd variable
    (MMColParam2) solves that
    particular issue.
    Do I need additional ( ) anywhere considering it is an OR
    though?
    Thanks.
    nath.
    "Nancy *Adobe Community Expert*" <[email protected]>
    wrote in message
    news:[email protected]...
    >I would think so .. now that you have the core statement
    working .. try
    >adding the other portions. Put the main statement in ( )
    and add the
    >others. Like this:
    >
    > SELECT *
    > FROM dbo.qryOrders
    > WHERE (orderID IN (SELECT qryPaidOrders.orderID FROM
    qryPaidOrders)
    > ORDER BY orderdate ASC) AND (customerid = MMColParam1)
    AND (vanopID =
    > MMColParam2)
    >
    > See what that gives you and fiddle with those till you
    get what you want.
    >
    >
    > --
    > Nancy Gill
    > Adobe Community Expert
    > BLOG:
    http://www.dmxwishes.com/blog.asp
    > Author: Dreamweaver 8 e-book for the DMX Zone
    > Co-Author: Dreamweaver MX: Instant Troubleshooter
    (August, 2003)
    > Technical Editor: DMX 2004: The Complete Reference, DMX
    2004: A
    > Beginner's
    > Guide, Mastering Macromedia Contribute
    > Technical Reviewer: Dynamic Dreamweaver MX/DMX: Advanced
    PHP Web
    > Development
    >
    >
    >
    >
    > "tradmusic.com" <[email protected]> wrote
    in message
    > news:[email protected]...
    >> Hi,
    >>
    >> After a bit of twiddling, I changed the statement to
    this:
    >>
    >> SELECT *
    >> FROM dbo.qryOrders
    >> WHERE orderID IN (SELECT qryPaidOrders.orderID FROM
    qryPaidOrders)
    >> ORDER BY orderdate ASC
    >>
    >> ...and it displays only those records who appear in
    the Paid Orders
    >> table. If I change this to NOT IN, it displays only
    the orders in the
    >> Orders table.
    >>
    >> Ideal, but I need to apply the customerID and
    vanopID variables....is
    >> that possible within this one statement?
    >>
    >> Really appreciate the help,
    >> Regards
    >> Nath.
    >>
    >> "Nancy *Adobe Community Expert*"
    <[email protected]> wrote in message
    >> news:[email protected]...
    >>> You've added to it since the first post. Take
    out the customerID and
    >>> vanopID parts and try focusing on just the
    orderID part. Get that
    >>> working first.
    >>>
    >>> I would try seeing if you can select those
    orderID's that are IN the
    >>> subquery first .. that would see whether or not
    the problem is the NOT
    >>> .. which should work .. but let's see first
    whether the culprit is the
    >>> query structure or not. See if you can select
    the orderID's that are in
    >>> the paid orders table from the main query.
    >>>
    >>>
    >>> --
    >>> Nancy Gill
    >>> Adobe Community Expert
    >>> BLOG:
    http://www.dmxwishes.com/blog.asp
    >>> Author: Dreamweaver 8 e-book for the DMX Zone
    >>> Co-Author: Dreamweaver MX: Instant
    Troubleshooter (August, 2003)
    >>> Technical Editor: DMX 2004: The Complete
    Reference, DMX 2004: A
    >>> Beginner's
    >>> Guide, Mastering Macromedia Contribute
    >>> Technical Reviewer: Dynamic Dreamweaver MX/DMX:
    Advanced PHP Web
    >>> Development
    >>>
    >>>
    >>> "tradmusic.com"
    <[email protected]> wrote in message
    >>> news:[email protected]...
    >>>> Hi Nancy,
    >>>>
    >>>> Have just tried that, but it is still
    displaying records whose orderID
    >>>> is also in a record in the Paid Orders
    table?
    >>>>
    >>>> I've got:
    >>>>
    >>>> SELECT *
    >>>> FROM dbo.qryOrders
    >>>> WHERE customerID = MMColParam OR vanopID =
    MMColParam1 AND orderID NOT
    >>>> IN (SELECT qryPaidOrders.orderID FROM
    qryPaidOrders)
    >>>> ORDER BY orderdate ASC
    >>>>
    >>>> Hope you can help.
    >>>> Thanks. :o)
    >>>> Nath.
    >>>>
    >>>>
    >>>> "Nancy *Adobe Community Expert*"
    <[email protected]> wrote in message
    >>>> news:[email protected]...
    >>>>> Why couldn't your inner query just be
    SELECT orderID from
    >>>>> dbo.tblPaidOrders? Wouldn't the top 100%
    be all of them?
    >>>>>
    >>>>>
    >>>>> --
    >>>>> Nancy Gill
    >>>>> Adobe Community Expert
    >>>>> BLOG:
    http://www.dmxwishes.com/blog.asp
    >>>>> Author: Dreamweaver 8 e-book for the DMX
    Zone
    >>>>> Co-Author: Dreamweaver MX: Instant
    Troubleshooter (August, 2003)
    >>>>> Technical Editor: DMX 2004: The Complete
    Reference, DMX 2004: A
    >>>>> Beginner's
    >>>>> Guide, Mastering Macromedia Contribute
    >>>>> Technical Reviewer: Dynamic Dreamweaver
    MX/DMX: Advanced PHP Web
    >>>>> Development
    >>>>>
    >>>>>
    >>>>> "tradmusic.com"
    <[email protected]> wrote in message
    >>>>>
    news:[email protected]...
    >>>>>> Hi,
    >>>>>>
    >>>>>> Two tables. Orders (orderID = PK)
    and Paid Orders (orderID = FK)
    >>>>>> I want to display a recordset of
    orders from the Orders table where
    >>>>>> the order ID doesn't appear in the
    Paid Orders table.
    >>>>>>
    >>>>>> I have tried something like this:
    >>>>>>
    >>>>>> SELECT *
    >>>>>> FROM dbo.tblOrders
    >>>>>> WHERE orderID NOT IN ( SELECT TOP
    100 PERCENT tblPaidOrders.orderID
    >>>>>> FROM dbo.tblPaidOrders )
    >>>>>>
    >>>>>> ...no joy with that though. Would
    appreciate some guidance. Thank
    >>>>>> you.
    >>>>>>
    >>>>>> Regards
    >>>>>> Nath.
    >>>>>>
    >>>>>
    >>>>>
    >>>>
    >>>>
    >>>
    >>>
    >>
    >>
    >
    >

Maybe you are looking for