Query trouble

Hi,
I have a query which works fine. I add one extra table to the query and dont join it any other table, but i get no records back. Why is this happening? When you dont join a table to any other in a query, normally there would be too many records that are displayed.
Any ideas?
Thanks
JA

Sorry everybody. That was a silly mistake on my part. I typed in the name of table wrong. It was an urgent issue i needed fixed, which is why i rushed for the forums without looking closely. Very sorry to bother you guys.
Thanks a lot for your immideate replies.
Regards
JA

Similar Messages

  • Sql query trouble

    Hi i am having trouble getting my head around an sql query. The query:
    "SELECT t.pub_name, tl.accountno
    FROM tenant_login tl, tenants t
    WHERE t.pub_name = '"+name+"' AND t.accountno = tl.accountno";
    produces a list of pub names and account numbers when an account number exists both in tenant_login and tenants.
    How do i create a query that lists the pubname and account numbers where the account number exists in tenants but NOT in tenant_login?
    Thanks

    SELECT t.pub_name, tl.accountno
    FROM tenants t
    WHERE t.pub_name = '"+name+"' AND t.accountno not in
    (select accountno from tenant_login )one small change i think
    SELECT t.pub_name, t.accountno
    FROM  tenants t
    WHERE t.pub_name = '"+name+"' AND t.accountno not in
    (select accountno from tenant_login )

  • Query troubles

    I have a table in my database called message_builder. It is probably badly designed and looks like this
    message_builder(message_ID, sent_business_ID1, sent_business_ID2, sent_business_ID3)
    Another table business looks like this:
    business(business_ID, name)
    I want to write a query that returns each row of the message_builder table but instead of returning the business IDs I want it to return the names of the businesses (so do a join with the business table).
    Is this possible or do I need to redesign my tables?
    So for example if the first row returned the following busiiness IDs - 1, 3, 5
    Then the result of the query would read:
    business1_name, business3_name, business5_name
    Thanks for your help,
    Wallace

    Something like
    SELECT mb.message_ID,
           b1.name,
           b2.name,
           b3.name
      FROM message_builder mb,
           business        b1,
           business        b2,
           business        b3
    WHERE mb.sent_business_id1 = b1.business_id
       AND mb.sent_business_id2 = b2.business_id
       AND mb.sent_business_id3 = b3.business_idJustin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • Query trouble with DI Server

    Hello everybody,
    I'm trying to execute SQL with DI Server. This is my SOAP-command:
    <env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
      <env:Header>
        <SessionID>63089993-AC37-4225-845D-D9722A50D5A7</SessionID>
      </env:Header>
      <env:Body>
        <dis:ExecuteSQL xmlns:dis="http://www.sap.com/SBO/DIS">
          <DoQuery>SELECT NULL AS Cat1Name, NULL AS Cat2Name, NULL AS Cat3Name, NULL AS Cat4Name,
              NULL AS Cat1Code, NULL AS Cat2Code, NULL AS Cat3Code, NULL AS Cat4Code
              FROM OITM
              WHERE 0 = 1 /* Dummy query to circumvent problems with XML-tag */
              UNION
              SELECT Cat1Name, Cat2Name, Cat3Name, Cat4Name, Cat1Code, Cat2Code, Cat3Code, Cat4Code
              FROM (
                SELECT cat1.Name AS Cat1Name, cat2.Name AS Cat2Name, cat3.Name AS Cat3Name, cat4.Name AS Cat4Name,
                cat1.Code AS Cat1Code, cat2.Code AS Cat2Code, cat3.Code AS Cat3Code, cat4.Code AS Cat4Code
                FROM @CATEGORY_4 cat4
                JOIN @CATEGORY_3 cat3 ON cat3.Code = cat4.U_Category_3
                JOIN @CATEGORY_2 cat2 ON cat2.Code = cat3.U_Category_2
                JOIN @CATEGORY_1 cat1 ON cat1.Code = cat2.U_Category_1
              UNION
                SELECT cat1.Name AS Cat1Name, cat2.Name AS Cat2Name, cat3.Name AS Cat3Name, NULL AS Cat4Name,
                  cat1.Code AS Cat1Code, cat2.Code AS Cat2Code, cat3.Code AS Cat3Code, NULL AS Cat4Code
                FROM @CATEGORY_3 cat3
                JOIN @CATEGORY_2 cat2 ON cat2.Code = cat3.U_Category_2
                JOIN @CATEGORY_1 cat1 ON cat1.Code = cat2.U_Category_1
              UNION
                SELECT cat1.Name AS Cat1Name, cat2.Name AS Cat2Name, NULL AS Cat3Name, NULL AS Cat4Name,
                  cat1.Code AS Cat1Code, cat2.Code AS Cat2Code, NULL AS Cat3Code, NULL AS Cat4Code
                FROM @CATEGORY_2 cat2 JOIN @CATEGORY_1 cat1 ON cat1.Code = cat2.U_Category_1
              UNION
                SELECT cat1.Name AS Cat1Name, NULL AS Cat2Name, NULL AS Cat3Name, NULL AS Cat4Name,
                  cat1.Code AS Cat1Code, NULL AS Cat2Code, NULL AS Cat3Code, NULL AS Cat4Code
                FROM @CATEGORY_1 cat1
              ) TMP
              WHERE ISNULL(Cat1Code, '') = '101'
              OR ISNULL(Cat2Code, '') = '101'
              OR ISNULL(Cat3Code, '') = '101'
              OR ISNULL(Cat4Code, '') = '101'
              OR '101' = ''</DoQuery>
        </dis:ExecuteSQL>
      </env:Body>
    </env:Envelope>
    When I run the SQL-bit in SQL Server 2005, all is fine. When I run this with DI Server, I get this response:
    <?xml version="1.0"?>
    <env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope">
      <env:Body>
        <env:Fault>
          <env:Code>
            <env:Value>env:Receiver</env:Value>
            <env:Subcode>
              <env:Value>229</env:Value>
            </env:Subcode>
          </env:Code>
          <env:Reason>
            <env:Text xml:lang="en">Failed to execute command</env:Text>
          </env:Reason>
          <env:Detail>
            <Statement>..The Query..</Statement>
            <Command>ExecuteSQL</Command>
            <SessionID>63089993-AC37-4225-845D-D9722A50D5A7</SessionID>
          </env:Detail>
        </env:Fault>
      </env:Body>
    </env:Envelope>
    Is this query too complex for the DI server to handle? Is it the subquery? Is it the unions?
    Thanks for your time!
    Vincent

    I have tried other queries in my application and they all don't seem to work anymore.
    I recently upgraded from PL39 to PL42. Has there been a change in the SOAP schema again?

  • SQL String Not a Query Trouble

    Just upgraded my JDeveloper and Oracle Application Server to 10.1.2 and some code that was working before no longer works. I suspect JDBC driver issues but I've been swapping jar files like a crazed loon and still no joy. Perhaps some here can give me a clue.. the exception I get is:
    nested exception is: org.exolab.castor.jdo.PersistenceException: Nested error: java.sql.SQLException: SQL string is not Query while executing UPDATE PER_USERS SET ACCTNM='paul',FIRSTNM='Paula',LASTNM='Sanders',MI='M',EMAIL='[email protected]',PHONEEXT='9362',ROLE_ID=1,DIVISION_ID=null,ERRTYPE_ID=null,ACTIVE='T' WHERE USER_ID=1 at ourcustomdbaccess.Query.execute(Query.java:112) at ...
    Query is a subclass of Castor's OQLQuery.
    Interestingly, before the upgrades this code would not work in JDev (9.0.4) but would work on the application server.
    Any suggestions appreciated!
    Paul

    Oooops ...
    Has the dang documentation writer (that's me) simply believed what the dang developer (that's the buddy sitting directly in front of me, nice guy by the way) has told him instead of testing it thoroughly enough.
    Unfortunately, only CHAR, CLNT, LANG, CUKY, UNIT and c are supported with operator && up to now.
    I adjust the documentation in SP09  (that's the current version, I'm working on). But maybe, that's also the SP, where the restriction will be abolished anyway (the problem as always in Open SQL - and meanwhile also in ABAP CDS - is, that each database must deliver the same result for all possible combinations and a lot of testing has to be done before the functionality can be released).
    Sorry for that and thanks for notifying me!
    Horst

  • AD query -- trouble with group.member list

    Hello,
    I'm attempting to create an AD query that filters for certain groups and all the members of those groups. I start with the groups table and filter to get the groups of interest. No problems so far.
    When I expand the group column to pick up the "member" column, I get group.member and the cell values have changed from "Record" to "List."  When I expand "List" I can tell I'm at the right level of granularity,
    because the number of rows has increased, and the group names are repeated for the number of members in a group. The problem is that the group.member field now shows "Record" again. I can't expand on it. And when I click on any of the "Record"
    links, I can see the individual's name.
    Any ideas on how I'm to get the name to show up in the full result set rather than needing to click on the "Record" link? Searching for "Power Query" with "record" has been...unhelpful (expectedly so).
    Thanks

    Gil,
    Thanks for the reply. I notice that in my query, displayName is null for all the records returned. I have been able to get the group name information from the sAMAccountName field, although I wonder if that is what is causing the issue when I attempt to
    expand. 
    Here are more details on my query stages:
    The first stage is with the following query (I left the "GL" filter visible since by itself it's not confidential):
    let
        Source = ActiveDirectory.Domains(<domain>),
        <domain> = Source{[Domain=<domain>]}[#"Object Categories"],
        group1 = <domain>{[Category="group"]}[Objects],
        #"Expand securityPrincipal" = Table.ExpandRecordColumn(group1, "securityPrincipal", {"sAMAccountName"}, {"securityPrincipal.sAMAccountName"}),
        #"Filtered Rows" = Table.SelectRows(#"Expand securityPrincipal", each Text.StartsWith([securityPrincipal.sAMAccountName], "GL"))
    in
        #"Filtered Rows"
    The second stage (1st screenshot) is immediately after I expand the group column and select "member." I show the bottom view, too, which shows the three records associated with this list (the correct number of users in that AD group).
    When I "expand" group.member, it changes from List to Record and there is now one row for each user in a group. However, when I go to pick the displayName column from group.member, it gives me the message "No columns were found." Yet,
    when I select the group.member value, I can see in the view below that there is a displayName. (See 2nd screenshot.) Note that I filtered the records in the third screenshot to just a single group -- 3 records.
    Does this additional information help isolate what I might be experiencing?
    Here is the query to match the final screenshot:
    let
        Source = ActiveDirectory.Domains(<domain>),
        <domain> = Source{[Domain=<domain>]}[#"Object Categories"],
        group1 = <domain>{[Category="group"]}[Objects],
        #"Expand securityPrincipal" = Table.ExpandRecordColumn(group1, "securityPrincipal", {"sAMAccountName"}, {"securityPrincipal.sAMAccountName"}),
        #"Filtered Rows" = Table.SelectRows(#"Expand securityPrincipal", each Text.StartsWith([securityPrincipal.sAMAccountName], "GL")),
        #"Expand group" = Table.ExpandRecordColumn(#"Filtered Rows", "group", {"member"}, {"group.member"}),
        #"Expand group.member" = Table.ExpandListColumn(#"Expand group", "group.member"),
        #"Expand top" = Table.ExpandRecordColumn(#"Expand group.member", "top", {"name"}, {"top.name"}),
        #"Removed Columns" = Table.RemoveColumns(#"Expand top",{"msExchIMRecipient", "ciscoEcsbuUMAttributes", "posixGroup", "top.name", "msExchBaseClass",
    "msExchCustomAttributes", "mailRecipient"})
    in
        #"Removed Columns"
    Scott C.

  • Sorting Query Trouble

    Try as I might I cannot get sorting to work on my screen.
    I have an child entity "orders" that shows the orders made for the parent entity when a specific parnt name is selected.
    On the screen I have several tabs showing the grids for orders but none of my table or screen queries is sorting the grids properties in the order defined by a query.
    I am trying to sort by a boolean "Reviewed" check box and put the ones checked in order alphabetically by string "name".
    Then the ones that are not checked or null in alphabetical order. Since no query would even function for some unknow reason.
    I tried just hitting the sort at the top of the "reviewed" column but it only orders them by True false null and not alphabetically.
    Note too Name comes from a related table one "Name" to many "Orders".
    Can you think of anything I might be doing wrong?

    I think you are on the right track here. I want to edit the child entity manually but I don't know how. I went to the edit query for the child entity on the screen but there is no option to add code to manually sort or filter for a screen query in VS LS
    2012. Ideally I would like to sort all instances of the grid control by Monogram or MonogramC(a calculated field) AND by Reviewed(a boolean) OR just filter the specific Grid under one of the tabs the Grid is named MedicationOrderDetails5.
    How do I do this I am not sure about even the code to use I have thought of adding the following to the screen code. How would you code something like this?
    using System;
    using System.Linq;
    using System.IO;
    using System.IO.IsolatedStorage;
    using System.Collections.Generic;
    using Microsoft.LightSwitch;
    using Microsoft.LightSwitch.Framework.Client;
    using Microsoft.LightSwitch.Presentation;
    using Microsoft.LightSwitch.Presentation.Extensions;
    //added to alow OLE DB data set code
    using System.Data;
    //using System.Data.OleDb;
    //added for Process Start statement
    using System.Diagnostics;
    using System.Linq.Expressions;
    namespace LightSwitchApplication
    public partial class TimesAndMARs
    partial void TimesAndMARs_InitializeDataWorkspace(List<IDataService> saveChangesTo)
    // Write your code here.
    //MedicationOrderDetails5
    partial void Reviewed_Filter(ref Expression<Func<MedicationOrderDetail, bool>> filter)
    filter = e => e.Reviewed != true;
    partial void OrderedByMonoramCalculatedField_PreprocessQuery
    (short? MonogramC, ref IQueryable<MedicationOrderDetail> query)
    query = (from myOrder in query
    where myOrder.MonogramC.Count() > 0
    orderby myOrder.MonogramC ascending
    select myOrder);

  • Query trouble - EXISTS doesnt work like I thought

    EXISTS is not behaving like I had hoped.
    Help would be much appreciated
    SELECT count(*) from OPPS
    WHERE OPP_CODE = "A"
    AND
    EXISTS (
    SELECT * FROM OPP_SUB_TABLE S, OPPS O
    WHERE S.ID = O.ID AND
    S.DTYPE = "1" AND S.DSUBTYPE = "2"
    There are 14000 rows in OPPS where OPP_CODE="A"
    There are only 31 rows in OPP_SUB_TABLE that have
    both DTYPE = "1" and DSUBTYPE = "2"
    I thought exists would work like an IN sort of, bringing me only 31 results.
    Instead I get all 14000, what I am missing here?

    EXISTS is like a boolean operation. It will return the row in your outer query if at least one row exists in your subquery.
    Because you haven't coordinated the subquery with your outer query, every row will be returned (apparently because your inner query always returns a row).
    I'm guessing you meant something like this:
    SELECT count(*)
    FROM   OPPS O
    WHERE  O.OPP_CODE = 'A'
    AND    EXISTS (SELECT 1
                   FROM   OPP_SUB_TABLE S
                   WHERE  S.ID = O.ID
                   AND    S.DTYPE = '1'
                   AND    S.DSUBTYPE = '2'
    ;(fixed the double quotes per Warren's example)
    Message was edited by:
    Eric H

  • Lion upgrade: Spotlight query trouble

    I upgraded to Lion this morning on my mid-2009 4Gb RAM MacBook Pro. Whenever I type something into Spotlight now, on the second keystroke it freezes, then all the icons to the left of spotlight disappear, blink and then return. I can't do a spotlight search :-(
    I tried resetting the index with mdutil. It got rebuilt. I still have the problem.
    I now notice I seem to be too late to write the Lion download to DVD. How can I reinstall cleanly now?

    Thanks. Well it seems on the french app store it is currently impossible to re-download lion :-( Telephone support person said it should be soon possible. She advised me to reinstall by rebooting and hit [Command] [R] on startup. We'll see!
    When spotlight crashes I am seeing this error in the console:
    Process:         SystemUIServer [1007]
    Path:            /System/Library/CoreServices/SystemUIServer.app/Contents/MacOS/SystemUIServer
    Identifier:      com.apple.systemuiserver
    Version:         1.7 (352)
    Build Info:      SystemUIServer-352000000000000~7
    Code Type:       X86-64 (Native)
    Parent Process:  launchd [140]
    Date/Time:       2011-08-05 16:23:23.880 +0200
    OS Version:      Mac OS X 10.7 (11A511)
    Report Version:  9
    Crashed Thread:  6  Dispatch queue: com.apple.root.default-priority
    Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
    Exception Codes: KERN_INVALID_ADDRESS at 0x0000000000000020
    VM Regions Near 0x20:
    -->
        __TEXT                 0000000101bc7000-0000000101c2a000 [  396K] r-x/rwx SM=COW  /System/Library/CoreServices/SystemUIServer.app/Contents/MacOS/SystemUIServer
    Application Specific Information:
    com.apple.syncservices.sync_menu
    com.apple.menuextra.bluetooth
    com.apple.menuextra.TimeMachine
    com.apple.menuextra.airport
    com.apple.scriptmenu
    com.apple.menuextra.displays
    com.apple.menuextra.volume
    com.apple.menuextra.battery
    com.apple.menuextra.textinput
    com.apple.menuextra.clock
    com.apple.menuextra.appleuser
    objc[1007]: garbage collection is OFF
    Thread 0:: Dispatch queue: com.apple.main-thread
    0   libsystem_kernel.dylib                  0x00007fff8657c67a mach_msg_trap + 10
    1   libsystem_kernel.dylib                  0x00007fff8657bd71 mach_msg + 73
    2   com.apple.CoreGraphics                  0x00007fff8db900b2 _CGSSynchronizeWindowBackingStore + 148

  • BPC Client Logging, what does this mean?

    I've been having trouble with my queries returning data. Sometimes my EVDREs will hang long after the query ends on BW. I looking in the client logs C:\Documents and Settings\dcarey\My Documents\BPC\Logging\. I noticed the logs are filling up with the the following error: What is the source of this error? Is it causing my query trouble?
    ==============[BPC Exception Logging]==============
    [Message Type] : ERROR
    [Job Name]     : Business Planning and Consolidation ActionPane.GetNameItemOfWS_1
    [DateTime]     : 6/2/2010 3:07:57 PM
    [UserId]       :
    [Exception]
        DetailMsg  : {Exception from HRESULT: 0x800A03EC}
    ==============[BPC Exception Logging End ]==============

    Hello,
    is there any hint, what might cause this error message?
    We are currently facing the message and have problems running reports
    Searching SDN, SAP Notes or even Goog.. with search machines only lead to this thread.
    Any help is appreciated!
    Regards
    Steve
    PS: We are currently on BPC 7.0 SP5

  • Gracenotes seems to causing problems.

    Since yesterday I have been unable to import CDs to my itunes. The only reason I can think of is that yesterday itunes asked me did I want to use gracenotes, I clicked yes and since then the problems started. It's a PC windows 7, I'm using.

    Interesting. I haven't had MusicMatch Jukebox installed on a PC for (literally) five years, but it used to try to do Gracenote queries at the same time as iTunes versions 4.7 and 4.7.1 when I inserted a CD to do an iTunes import. So I'm not altogether surprised that it (or a particular version of it) could be causing Gracenote query trouble with newer versions of iTunes.
    If you're not using your MusicMatch Jukebox, uninstalling it should get rid of your mmjb.exe process permanently, Scy. If you are using it, then your workaround of ending the mmjb.exe process prior to doing an import in iTunes seems to be the way to go.

  • Trouble writing Query for Pivoting data from a table

    I am having a little trouble writing a query for converting the below table data into a pivot data. I am trying to write a query for which if I give a single valid report_week date as input it should give me the data for that week and also provide two extra columns, one which gives the data of last week for the same countries and the second column which gives the difference of numbers in both the columns(i.e. COUNT - COUNT_LAST_WEEK).
    REPORT_WEEK     DIVISION     COUNT
    9/26/2009     country1     81
    9/26/2009     country2     97
    9/26/2009     country3     12
    9/26/2009     country4     26
    9/26/2009     country5     101
    10/3/2009     country1     85
    10/3/2009     country2     98
    10/3/2009     country3     10
    10/3/2009     country4     24
    10/3/2009     country5     101
    10/10/2009     country1     84
    10/10/2009     country2     98
    10/10/2009     country3     10
    10/10/2009     country4     25
    10/10/2009     country5     102
    For example, if I give input as 10/10/2009, the output should be as give below.
    REPORT_WEEK     DIVISION     COUNT     COUNT_LAST_WEEK     DIFFERENCE
    10/10/2009     country1     84     85     -1
    10/10/2009     country2     98     98     0
    10/10/2009     country3     10     10     0
    10/10/2009     country4     25     24     1
    10/10/2009     country5     102     101     1
    For example, if I give input as 10/3/2009, the output should be as give below.
    REPORT_WEEK     DIVISION     COUNT     COUNT_LAST_WEEK     DIFFERENCE
    10/3/2009     country1     85     81     4
    10/3/2009     country2     98     97     1
    10/3/2009     country3     10     12     -2
    10/3/2009     country4     24     26     -2
    10/3/2009     country5     101     101     0
    Can anyone please shed some light on Query building for the above scenarios.
    Thank you
    SKP
    Edited by: user11343284 on Oct 10, 2009 7:53 AM
    Edited by: user11343284 on Oct 10, 2009 8:28 AM

    I assume there is no gap in report weeks. If so:
    SQL> variable report_week varchar2(10)
    SQL> exec :report_week := '10/10/2009'
    PL/SQL procedure successfully completed.
    with t as (
               select to_date('9/26/2009','mm/dd/yyyy') report_week,'country1' division,81 cnt from dual union all
               select to_date('9/26/2009','mm/dd/yyyy'),'country2',97 from dual union all
               select to_date('9/26/2009','mm/dd/yyyy'),'country3',12 from dual union all
               select to_date('9/26/2009','mm/dd/yyyy'),'country4',26 from dual union all
               select to_date('9/26/2009','mm/dd/yyyy'),'country5',101 from dual union all
               select to_date('10/3/2009','mm/dd/yyyy'),'country1',85 from dual union all
               select to_date('10/3/2009','mm/dd/yyyy'),'country2',98 from dual union all
               select to_date('10/3/2009','mm/dd/yyyy'),'country3',10 from dual union all
               select to_date('10/3/2009','mm/dd/yyyy'),'country4',24 from dual union all
               select to_date('10/3/2009','mm/dd/yyyy'),'country5',101 from dual union all
               select to_date('10/10/2009','mm/dd/yyyy'),'country1',84 from dual union all
               select to_date('10/10/2009','mm/dd/yyyy'),'country2',98 from dual union all
               select to_date('10/10/2009','mm/dd/yyyy'),'country3',10 from dual union all
               select to_date('10/10/2009','mm/dd/yyyy'),'country4',25 from dual union all
               select to_date('10/10/2009','mm/dd/yyyy'),'country5',102 from dual
    select  max(report_week) report_week,
            division,
            max(cnt) keep(dense_rank last order by report_week) cnt_this_week,
            max(cnt) keep(dense_rank first order by report_week) cnt_last_week,
            max(cnt) keep(dense_rank last order by report_week) - max(cnt) keep(dense_rank first order by report_week) difference
      from  t
      where report_week in (to_date(:report_week,'mm/dd/yyyy'),to_date(:report_week,'mm/dd/yyyy') - 7)
      group by division
      order by division
    REPORT_WE DIVISION CNT_THIS_WEEK CNT_LAST_WEEK DIFFERENCE
    10-OCT-09 country1            84            85         -1
    10-OCT-09 country2            98            98          0
    10-OCT-09 country3            10            10          0
    10-OCT-09 country4            25            24          1
    10-OCT-09 country5           102           101          1
    SQL> exec :report_week := '10/3/2009'
    PL/SQL procedure successfully completed.
    SQL> /
    REPORT_WE DIVISION CNT_THIS_WEEK CNT_LAST_WEEK DIFFERENCE
    03-OCT-09 country1            85            81          4
    03-OCT-09 country2            98            97          1
    03-OCT-09 country3            10            12         -2
    03-OCT-09 country4            24            26         -2
    03-OCT-09 country5           101           101          0
    SQL> SY.

  • Big Troubles on designing Query about special customers' counting

    Hello buddies:
    I meet a problem on designing Query about special customers' counting. Let me describe the requirment first.  I want to create a query with BEX , and there is a key figure with very special logic.
    That is: to list the counts of the customers which has more than one sales records in a time period from sales data. 
    For example :
    when the user excute the query , he or she must input a time period ( 2007.01~2007.03 e.g)
    then the query output as follow:
    District          Cust-sount
    North-Zone       100
    South-Zone      120
    The Main trouble are :
    1. Threr are no document number in the detail of sales data document records. so I could not count the sales times with document number.
    2. The time period is not fixed value, it depends on the user's input, so I can not define the counting logic in the update rule or in the query with fixed time period.
    Anybody who met similar requirement pls show me your hand and give your solutions, thanks very much.
    Jason

    Hi,
        Your solution sounds a good way to count the distinct customers. but in my case, one salse line item must not be recognize as one sales record, instead,  one customer's all sales line items occurs in one day must be  recognize as one sales record ( or we say that one sales behavior).
    for example:
    customer     product    quantity   date
    cust001       prod001        10       2007.06.06
    cust001       prod002        20       2007.06.06
    the two line items above means one sales record for the customer "cust001".
    so I could not simply use the CKF : (( Counter ) *FV2 ) > 1 .
    Best Regards,
    Jason

  • Having alot of trouble with a query

    Hey, I'm having trouble with a query for an assignment. The questions states
    Find the name of the highest earning employee in each location, excluding managers, salespeople and the president
    The problem I'm having is that my query returns the highest earning employee from each location perfectly, but one of those returned is a salesperson, so the next highest earning person in that location should be returned.
    We are also not allowed to create a temporary table
    Here's my code so far
    select
    e.first_name,
    e.last_name,
    e.salary,
    l.regional_group
    from employee e
    inner join department d
    on d.department_id = e.department_id
    inner join location l
    on l.location_id = d.location_id
    where e.salary = (select max(e2.salary) from employee e2
    inner join department d2
    on d2.department_id = e2.department_id
    inner join location l2
    on l2.location_id = d2.location_id
    where l2.location_id = l.location_id
    and e.job_id !=672;
    the job_id refers to what job title they have
    and here's the schema below
    Schema
    Any help you could give me on this would be fantastic as I have been pulling my hair out over this for the last day.
    Edited by: 837562 on 17-Feb-2011 02:14

    Maybe you can try the below:
    with job_location as
    select 1 location_id, 'loc1' regional_group from dual
    union
    select 2 location_id, 'loc2' regional_group from dual
    department as
    select 1 department_id, 'dept1' dept_name, 1 location_id from dual
    union
    select 2 department_id, 'dept2' dept_name, 2 location_id from dual
    job_FUNCTION as
    select 1 job_id, 'MANAGER' job_function from dual
    UNION
    select 2 job_id, 'SALES' job_function from dual
    UNION
    select 3 job_id, 'PRESIDENT' job_function from dual
    UNION
    select 4 job_id, 'REST_1' job_function from dual
    UNION
    select 5 job_id, 'REST_2' job_function from dual
    employee as
    select 1 employee_id, 'a' last_name, 100 salary, 1 department_id, 4 JOB_ID from dual union
    select 2 employee_id, 'b' last_name, 200 salary,1, 5 from dual union
    select 3 employee_id, 'c' last_name, 300 salary,1, 2 from dual union
    select 4 employee_id, 'd' last_name, 400 salary,1, 2 from dual union
    select 5 employee_id, 'e' last_name, 500 salary,2, 3 from dual union
    select 6 employee_id, 'f' last_name, 600 salary,2, 3 from dual union
    select 7 employee_id, 'g' last_name, 700 salary,2, 4 from dual union
    select 8 employee_id, 'h' last_name, 800 salary,2, 4 from dual
    select
    regional_group, employee_id, max_salary
    from
    select e.regional_group, b.department_id, employee_id, salary, max(b.salary) over (partition by b.department_id order by b.department_id) max_salary
    from
    employee b,
    job_function c,
    department d,
    job_location e
    where
    b.job_id = c.job_id and
    b.department_id = d.department_id and
    e.location_id = d.location_id and
    c.job_id not in (1,2,3) 
    ) where salary = max_salary;
    "REGIONAL_GROUP"     "EMPLOYEE_ID"     "MAX_SALARY"
    "loc1"     "2"     "200"
    "loc2"     "8"     "800"

  • Trouble With Query Between Dates:

    Hello Again,
    The query below is giving some trouble in that the line where 'CURRENT_DATE' is between 'START_DATE' and 'END_DATE.
    The query returns records close to those dates but some missing on the END_DATE. I was wondering if there is 'time at play here? How is only the date component used for the search?
    select * from (
    SELECT TO_CHAR (LEAVE.START_DATE, 'DD-MON-YY') AS Start_Date,
    TO_CHAR (LEAVE.END_DATE, 'DD-MON-YY') AS end_date,
    TO_CHAR (CURRENT_DATE, 'DD-MON-YY')AS CURRENT_DATE,
    LEAVE.NAME as NAME,
    LEAVE.ID as ID,
    LEAVE.DAYS as Days,
    LEAVE.SUPERVISOR as Supervisor,
    LEAVE.LEAVE_TYPE,
    FROM "LEAVE"
    WHERE CURRENT_DATE BETWEEN start_date AND end_date
    Kind Regards,
    Steve Welch

    Hi Steve,
    You should be aware that the Oracle datatype DATE also includes a time component.
    select to_char(current_date,'DD-MON-YYYY HH24:MI:SS') date_and_time from dual;
    DATE_AND_TIME       
    18-AUG-2011 13:29:49 Could it be that you are missing some records because they have a time which falls outside your condition?
    Regards
    Andre

Maybe you are looking for