Simple query returns wrong results in Sql 2012

On my Windows 8 box running Sql 2012 11.0.3128, this query returns an IncludeCount of 0 and an ExcludeCount of 1.
On my Windows 7 box running Sql 2008 10.50.2550 this query returns an IncludeCount of 3 and an ExcludeCount of 1, which is correct.
In short, it runs properly on these versions of OS and Sql's:
Windows 2008 R2 + Sql 10.50.2550
Windows 2008 R2 + Sql 10.50.4000
Windows 2012 SP1 + Sql 11.0.3000
Windows 7 + Sql 11.0.2100
And gives incorrect results on these OS's and Sql's (so far, tested):
Windows 8 Enterprise + Sql 11.0.3128
Windows 2008 R2 + Sql 10.50.2550
I wondered if anyone else can reproduce this?  I can't figure out the magic combination of OS and SQL version this breaks on.
In all scenarios, the resulting @filters table is populated correctly, and the [Include] column is properly set to a 1 or a 0, so why aren't the other variables being properly set?
If I change the [ID] column to NONCLUSTERED, it works fine, too.  It doesn't matter if @filters is a TVP or a temp table or an actual table, same (incorrect) results in each case.
DECLARE @filters TABLE([ID] bigint PRIMARY KEY, [Include] bit)
DECLARE @excludecount int = 0
DECLARE @includecount int = 0
DECLARE @id bigint
INSERT INTO @filters ([ID])
VALUES (1), (3), (4), (-7)
UPDATE @filters SET
    @id = [ID],
    @includecount = @includecount + (CASE WHEN @id > 0 THEN 1 ELSE 0 END),
    @excludecount = @excludecount + (CASE WHEN @id < 0 THEN 1 ELSE 0 END),
    [Include] = CASE WHEN @id > 0 THEN 1 ELSE 0 END,
    [ID] = ABS(@id)
SELECT @includecount as IncludeCount, @excludecount as ExcludeCount
SELECT * FROM @filters

What part is undocumented?
http://technet.microsoft.com/en-us/library/ms177523.aspx
The above link states I can update variables inside an UPDATE statement ...
But it does not say what the correct result of what you are trying to would be. Variable assignment in UPDATE only makes sense if the UPDATE hits one row. If the UPDATE matches several rows, which value you the variable is set to is not defined.
It gets even more complicated when you have the variable on both sides of the expression. But I'd say that the only two values that makes as the final value of @includecount 0. An UPDATE statement, like other DML statements in SQL, is logically defined
as all-at-once. There are no intermediate results. Therefore the only possible values are the initial value of @includecount plus the value of the CASE statement, which always should returns 0, since @id is NULL when the UPDATE statement starts to execute.
I'm afraid that what you have is nonsense from a language perspective, and the result is undefined. Whenever you get different results from a query depending on whether you have certain indexes in place, you know that the query is indeterministic. There
are certainly part of SQL that are indeterministic, for instance ORDER BY on a non-unique columns. But in this particular case you have also wandered out into the land that is also undefined.
I'm not sure what you are trying to achieve, but I can only advice you to go back to the drawing board.
Erland Sommarskog, SQL Server MVP, [email protected]

Similar Messages

  • Simple Query returns no result

    We have a problem with a simple query on a "old" Table in our Database. The Table has following Structure:
    CREATE TABLE <table_name>
        ROLE_ID INTEGER NOT NULL,
        ROLE_NAME VARCHAR (99) ascii NOT NULL,
        OBJECTDATA LONG BYTE,
        UNIQUE (ROLE_NAME)
    The table containts two rows and following querys get these results:
    select role_id, role_name from <schema>.<table_name>
    --> 2 rows
    select role_id, role_name from <schema>.<table_name>
    order by role_id
    --> 2 rows
    select role_id, role_name from <schema>.<table_name>
    order by role_name
    --> 0 rows  ?? confusion
    When we create a "new" table with the same structure, and insert the same content to this new table,  the queries are working correctly.
    What happened with our "old" table,  so that these simple queries don't function anymore?
    (Database Kernel    7.6.05   Build 009-123-191-997)
    thx
    gerri
    Edited by: Gerfried on Jul 17, 2009 11:42 AM

    Ok, Gerfried send me the dump file and this is what was in it:
    INV ROOT/LEAF 15857  perm  entries : 0        [block 0]
         bottom  : 81         filevers: dummy     convvers: 9
                                                  writecnt: 1
    00001      nodepage.pno: 15857             nodepage.pt : data
    00006      nodepage.pt2: inv               nodepage.chk: checksumData
    00008      nodepage.mde: empty
    08181      nd_checksum : 61937             nodepge2.pno: 15857
    08189      nodepge2.pt : data              nodepge2.pt2: inv
    08191      nodepge2.chk: checksumData
    08192      nodepge2.mde: empty
    00009      nd_bottom   : 81                nd_rec_cnt  : 0
    00017      nd_level    : 0
    00019      nd_filestate: empty
    00020      nd_sorted   : false             nd_root     : 15857/F13D0000
    00025      nd_right    : nil_pno           nd_left     : nil_pno
    00033      nd_last     : nil_pno           nd_conv_vers: 9
    00045      nd_str_vers : nil_pno           nd_file_vers: dummy
    00052      ndPageVersio: 0                 nd_inv_usage: 0
    00057      nd_leaf_cnt : 1                 nd_treeleavs: nil
    00065      nd_trans_id : nil               ndInvRoot   : nil_pno
    00077      nd_write_cnt: 1
    END OF FILE
    Obviously the reason for not delivering any data for the query is: this index is empty.
    See "nd_filestate: empty" !
    For some reasons (that I really don't know - sorry about that) this index had not been maintained anymore, since a very long time.
    "nd_conv_vers: 9" tells us that it was the 9th savepoint that wrote down this page to the disks and that it had not been touched since then.
    To view the current converter version you may just use the db_restartinfo command in dbmcli.
    If you were a SAP customer the next thing I'd check would be with which database version these indexes had been created, what the internal file state is etc. - just to figure out the root cause.
    As such an analysis is basically not possible via this forum all I can propose is to look for those indexes (containing 0 entries although the table has more rows) and rebuild them.
    This statement should do the trick:
    select i.owner, i.indexname, i.tablename, if.*
    from files if join files tf  on if.primaryfileid=tf.fileid
                   join indexes i on if.fileid=i.fileid
    where if.entrycount =0
    and if.type ='INDEX'
    and tf.entrycount >0
    best regards,
    Lars

  • Query returning wrong results - Help required.

    Hi All,
    I am having a query in which I have 10 records, 5 with stop time 1 and 5 with stop time 2.
    I have a scenario in which, I need to calculate the maximum,minimum for the records
    with stop time 1 and 2.
    What I did is, I selected all the 10 records using for loop. Within the loop
    I am trying to find the maximum and minimum. It is giving me wrong results.
    Please help me. My code is follows
    declare
         v_p1_min_stop_tm     number;
         v_p1_max_stop_tm     number;
         v_p2_min_stop_tm     number;
         v_p2_max_stop_tm     number;
    begin
         for i in(
              select
                   stop_tm
              from
                   sample_stop
              where
                   map_nbr = 16645 and
                   stop_dt = '05-sep-08'
         )loop
              if i.stop_tm = 1 then
                   select
                        min(i.stop_tm),
                        max(i.stop_tm)
                   into
                        v_p1_min_stop_tm,
                        v_p1_max_stop_tm
                   from
                        dual;
              elsif i.stop_tm = 2 then
                   select
                        min(i.stop_tm),
                        max(i.stop_tm)
                   into
                        v_p2_min_stop_tm,
                        v_p2_max_stop_tm
                   from
                        dual;
              end if;
         end loop;
         dbms_output.put_line('minimum p1 stop time : '|| v_p1_min_stop_tm);
         dbms_output.put_line('maximum p1 stop time : '|| v_p1_max_stop_tm);
         dbms_output.put_line('minimum p2 stop time : '|| v_p2_min_stop_tm);
         dbms_output.put_line('maximum p2 stop time : '|| v_p2_max_stop_tm);
    end;
    My o/p is :
    Minimum P1 stop time : 523
    Maximum P1 stop time : 523
    Minimum P2 stop time : 719
    Maximum P2 stop time : 719
    Here how can I make the data as two sets, one set with stop time 1 and
    other with stop time 2.
    Regards
    Raghu

    If the data type of stop_tm is varchar then try following
    declare
         v_p1_min_stop_tm number;
         v_p1_max_stop_tm number;
         v_p2_min_stop_tm number;
         v_p2_max_stop_tm number;
    begin
         for i in(select  stop_tm  from  sample_stop
              where
                   map_nbr = 16645 and
                   stop_dt = '05-sep-08'
              )loop
         if i.stop_tm = 1 then
              select min(to_number(i.stop_tm)), max(to_number(i.stop_tm))
                   into v_p1_min_stop_tm,v_p1_max_stop_tm
              from
                   dual;
         elsif i.stop_tm = 2 then
              select
                   min(to_number(i.stop_tm)),     max(to_number(i.stop_tm))
                   into
                   v_p2_min_stop_tm,v_p2_max_stop_tm
              from
                   dual;
         end if;
    end loop;
    dbms_output.put_line('minimum p1 stop time : '|| v_p1_min_stop_tm);
    dbms_output.put_line('maximum p1 stop time : '|| v_p1_max_stop_tm);
    dbms_output.put_line('minimum p2 stop time : '|| v_p2_min_stop_tm);
    dbms_output.put_line('maximum p2 stop time : '|| v_p2_max_stop_tm);
    end;
    / Regards
    Singh

  • Query returning wrong result set

    I am running the following query on 8.1.7 database. The query is
    SELECT Y.*, TEVStatus.lEndStatusFlag ENDSTATUSFLAG
    FROM
    (SELECT ROWNUM RANK, X.* FROM (SELECT lExceptionID ID,
    TEVException.sMonitorName MONNAME, sExcpStatus STATUS
    FROM TEVException WHERE (TEVException.lExceptionID IN
    (SELECT lExceptionID FROM TEVException WHERE
    sUserName_AssignedTo = 'vadmin')) ORDER BY
    TEVException.lExceptionID DESC) X)
    Y, TEVStatus WHERE (Y.RANK > 0 AND Y.RANK < 0 + 51 + 1) AND
    (STATUS = TEVStatus.sStatusName);
    The result is
    RANK ID MONNAME STATUS ENDSTATUSFLAG
    51 29 Type09B Open 0
    50 30 Type09A Open 0
    49 31 Type09E Open 0
    48 32 Type09F Open 0
    47 33 Type09G Open 0
    46 34 Type09I Open 0
    45 35 Type09C Open 0
    44 36 Type10A Open 0
    43 37 Type04A Open 0
    39 41 Type08A Open 0
    38 42 Type08C Open 0
    RANK ID MONNAME STATUS ENDSTATUSFLAG
    37 43 Type10B Open 0
    36 44 Type10E Open 0
    35 45 Type10C Open 0
    34 46 Type10F Open 0
    33 47 Type10D Open 0
    32 48 Type08B Open 0
    31 49 Type04B Open 0
    29 51 Type08D Open 0
    28 52 Type11E Open 0
    27 53 Type11A Open 0
    26 54 Type11D Open 0
    RANK ID MONNAME STATUS ENDSTATUSFLAG
    25 55 Type11C Open 0
    24 56 Type11B Open 0
    23 57 Type12A Open 0
    22 58 Type12B Open 0
    21 59 Type12C Open 0
    20 60 Type12E Open 0
    19 61 Type12A Open 0
    18 62 Type12B Open 0
    17 63 Type12E Open 0
    16 64 Type12C Open 0
    15 65 Type12D Open 0
    RANK ID MONNAME STATUS ENDSTATUSFLAG
    14 66 Type12D Open 0
    4 80 Type01A_Ravi Open 0
    3 83 Type01A_Ravi Open 0
    2 84 Type01A_Ravi Open 0
    1 87 Type01A_Ravi Open 0
    42 38 Type06E Closed 8500
    41 39 Type06A Closed 8500
    40 40 Type06B Closed 8500
    30 50 Type06C Closed 8500
    13 68 Type01A Closed 8500
    12 69 Type01A Closed 8500
    RANK ID MONNAME STATUS ENDSTATUSFLAG
    11 70 Type01A Closed 8500
    10 71 Type01A Closed 8500
    9 72 Type01A Closed 8500
    8 73 Type01A Closed 8500
    7 75 Type01A Closed 8500
    6 77 Type01A Closed 8500
    5 78 Type01A Closed 8500
    51 rows selected.
    In the above result, the RANK is not sorted properly and I
    expected ID in descending order. The table which I was querying
    had only about 100 records. I ran the same query on a larger
    record set and the result is fine. I get ID in descending order
    which I was expecting.
    Could someone please tell me whether any bug in this case or
    something wrong in the query

    Hi...
    Took a quick look at tour SQL and....
      SELECT Y.*
           , TEVStatus.lEndStatusFlag ENDSTATUSFLAG
        FROM ( SELECT ROWNUM RANK
                    , X.*
                 FROM ( SELECT lExceptionID ID
                             , TEVException.sMonitorName MONNAME
                             , sExcpStatus STATUS
                          FROM TEVException
                         WHERE ( TEVException.lExceptionID IN
                                 ( SELECT lExceptionID
                                      FROM TEVException
                                    WHERE sUserName_AssignedTo
                                          = 'vadmin'
                         ORDER BY TEVException.lExceptionID DESC
                      ) X
             ) Y
           , TEVStat us
       WHERE ( Y.RANK > 0
               AND
               Y.RANK < 0 + 51 + 1
         AND STATUS = TEVStatus.sStatusName ;
    Should "FROM ( SELECT ROWNUM RANK" be "FROM ( SELECT ROWNUM,
    RANK"?
    RANK is a reserved word, an analytic function.
    Is "ORDER BY TEVException.lExceptionID DESC" doing anything?  I
    would drop it..
    Hope this helps. Good Luck.

  • Union_all query returns wrong results

    I have 6 individual queries that combine together using "union_all". If I run it, it returns 6084 records, see example 1.
    Example 1:
    sql1
    union_all
    sql2
    unionl_all
    sql3
    sql6;
    if I do it this way, example2, I get only 3821 records. Is there a bug in Oracle 11g? I select everything from 6084 records, I should get them all, correct?
    Example 2:
    select * from
    sql1
    union_all
    sql2
    unionl_all
    sql3
    sql6
    note that I use "union_all" because the computer does not take it without the underscore.

    user557594 wrote:
    Your queries do not deal with thousand of rows. My queries worked ok before the upgrade to 11g. I just want to know if there is a bug related to union all in 11g.If you believe that you are encountering a bug, you really should be posting this over on Metalink (My Oracle Support). When you do, you'll want to specify at a minimum the 4 digit Oracle version you are using (11g could mean either of two major releases and a few different patchsets).
    I'm sure if you search My Oracle Support, you'll find at least one bug in whatever version of 11g you're using that occurs when UNION ALL is used (though I'll wager that you need two or three other conditions to be true as well). If you open a ticket, however, Oracle Support can determine whether you are actually encountering an error and/or whether you've encountered any of the published bugs, an unpublished bug, or a new bug. Once you know that, Oracle Support may or may not have a patch for you.
    Unfortunately, if you can't post a test case that would allow us to reproduce the problem locally, it's going to be hard for us to provide much assistance. Of course, Oracle Support will also need a reproducible test case, but they can probably help you work through the process of putting one together complete with sample data and a query plan.
    Justin

  • Please Help Urgent:Fast Search returning wrong result sets

    Hi All,
    We are facing below issue with fast search.
    Currently in My project  when  we are searching  for a phrase it is returning wrong result sets.
    For example if we search for “Endura”, It is returning documents related to
    Endura  as well as Centura.
    But the expected results are only Endura documents.
    When we look in to the documents we didn’t find the search term (“Endura” ) either inside document content or in its meta data.
    In order to resolve the issue we tried the below steps
    1-     
    We manually edited and saved the document, to ensure the appropriate Guid association to metadata.
    2-     
    Index reset
    3-     
    Full crawl
    But no luck  so far.
    Please help.Thanks in advance.
    Regards
    Subrat

    Subrat,
    This may be related to spellchecking or may be synonym. Spellcheck is based on indexed terms.
    The best test would be to run the queries from qrserver (13280) and then look at the spellcheck query transformations. If spellchecking is not doing it, then you must have a synonym setup .Check your keyword/synonyms from the SharePoint side. 

  • Same Query returning different result (Different execution plan)

    Hi all,
    To day i have discovered a strange thing: a query that return a different result when using a different execution plan.
    The query :
    SELECT  *
      FROM schema.table@database a
    WHERE     column1 IN ('3')
           AND column2 = '101'
           AND EXISTS
                  (SELECT null
                     FROM schema.table2 c
                    WHERE a.column3 = SUBSTR (c.column1, 2, 12));where schema.table@database is a remote table.
    when executed with the hint /*+ ordered use_nl(a c) */ these query return no result and its execution plan is :
    Rows     Row Source Operation
          0  NESTED LOOPS  (cr=31 r=0 w=0 time=4894659 us)
       4323   SORT UNIQUE (cr=31 r=0 w=0 time=50835 us)
       4336    TABLE ACCESS FULL TABLE2 (cr=31 r=0 w=0 time=7607 us)
          0   REMOTE  (cr=0 r=0 w=0 time=130536 us)When i changed the execution plan with the hint /*+ use_hash(c a) */
    Rows     Row Source Operation
       3702  HASH JOIN SEMI (cr=35 r=0 w=0 time=497839 us)
      22556   REMOTE  (cr=0 r=0 w=0 time=401176 us)
       4336   TABLE ACCESS FULL TABLE2 (cr=35 r=0 w=0 time=7709 us)It seem that when the execution plan have changed the remote query return no result.
    It'is a bug or i have missed somthing ?
    PS: The two table are no subject to insert or update statement.
    Oracle version : 9.2.0.2.0
    System version : HP-UX v1
    Thanks.

    H.Mahmoud wrote:
    Oracle version : 9.2.0.2.0
    System version : HP-UX v1Hard to say. You're using a very old and deprecated version of the database, and one that was known to contain bugs.
    9.2.0.7 was really the lowest version of 9i that was considered to be 'stable', but even so, it's old and lacking in many ways.
    Consider upgrading to the latest database version at your earliest opportunity. (or at least apply patches up to the latest 9i version before querying if there is bugs in your really low buggy version)

  • Simple query with like return wrong result

    Hi,
    I run simple query with like.
    If I use parameter I get wrong results.
    If I use query without parameter results are ok.
    My script:
    ALTER SESSION SET NLS_SORT=BINARY_CI;
    ALTER SESSION SET NLS_COMP=LINGUISTIC;
    -- drop table abcd;
    create table abcd (col1 varchar2(10));
    INSERT INTO ABCD VALUES ('122222');
    insert into abcd values ('111222');
    SELECT * FROM ABCD WHERE COL1 LIKE :1; -- wrong result with value 12%
    COL1
    122222
    *111222*
    select * from abcd where col1 like '12%'; -- result ok
    COL1
    122222
    I use Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
    and query run in Oracle SQL Developer 3.1.07.

    Hi,
    welcome to the forum.
    When you put some code please enclose it between two lines starting with {noformat}{noformat}
    i.e.:
    {noformat}{noformat}
    SELECT ...
    {noformat}{noformat}
    You should specify exactly how you run your code.
    If I run this statement in SQL Plus:SQL> ALTER SESSION SET NLS_SORT=BINARY_CI;
    Session altered.
    SQL> ALTER SESSION SET NLS_COMP=LINGUISTIC;
    Session altered.
    SQL>
    SQL> -- drop table abcd;
    SQL> create table abcd (col1 varchar2(10));
    Table created.
    SQL>
    SQL> INSERT INTO ABCD VALUES ('122222');
    1 row created.
    SQL> insert into abcd values ('111222');
    1 row created.
    SQL>
    SQL> SELECT * FROM ABCD WHERE COL1 LIKE :1;
    SP2-0552: Bind variable "1" not declared.
    SQL>
    I got this error. So I wonder how you set value 12%
    Please specify exactly how you run your test as we cannot reproduce your problem.
    Regards.
    Al                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • SSIS query returns no results - same query in SQL management studio works

    Hello,
    I'm running a very simple join to get a result set:
    SELECT dbo.sap_contracts.svc_id, dbo.sap_contracts.svc_code, dbo.sap_contracts.quantity, dbo.sap_contracts.start_date, dbo.sap_contracts.end_date
    FROM dbo.sap_contracts
    INNER JOIN dbo.contracts
    ON dbo.contracts.contract_id=dbo.sap_contracts.contract_id
    where customer_name='XXXXXXXXX'
    When I run this in SQL management studio it works fine and returns the list of existing "SAP contracts" in the DB (to compare to the customer's contracts actually in SAP).
    In SSIS (SQL 2012) I'm using an Execute SQL task to run this query and putting the full results set into a variable of type "object". I've done very similar things before and it worked fine. With this query in SSIS I get no results at all. Changing
    the variable type to "string" throws an error showing that the type being written to the variable is "DBNull" - so it seems that the query in SSIS returns no records, when in SQL management studio I get the 15 records that should be returned.
    Does anyone have any ideas of what could be wrong?
    Cheers
    Mark

    There are several connections to the DB in tasks before this one, and the task after this is a whole load of C# in a script task doing SOAP communications to the SAP ERP system to compare the result set from this SQL with the contracts in SAP ERP for the
    specific customer.
    Input variables are all correct (I've checked them about 15 times now with breakpoints on just about every task in the whole package) and I'm at the point of having to test everything in an attempt to see exactly what query is being sent to the SQL server
    and anything else I can do to see why nothing comes back. There is a almost complete lack of debugging tools in SSIS which doesn't make life any easier (something I've heard quite a few times in various forums).
    I'm tearing my hair out on this for half a day now and it's not funny any more, so apologies if I come across as a little frustrated.
    Cheers
    Mark

  • SQL Query with wrong result

    Hello.
    I have a query with LEFT OUTER JOIN that I think returns invalid results. Here are the problem details:
    CREATE TABLE DOGERR(
    IdDog INTEGER,
    SfPdg CHAR(1),
    IdVpl INTEGER,
    SfVpGot INTEGER,
    SfZrr CHAR(1)
    INSERT INTO DOGERR(IdDog, SfPdg, IdVpl, SfVpGot, SfZrr) VALUES (1, 'S', 1, 1, '7');
    INSERT INTO DOGERR(IdDog, SfPdg, IdVpl, SfVpGot, SfZrr) VALUES (2, 'S', 1, 1, '7');
    INSERT INTO DOGERR(IdDog, SfPdg, IdVpl, SfVpGot, SfZrr) VALUES (3, '$', 1, 2, 'C');
    COMMIT;
    CREATE UNIQUE INDEX DOGERR_PK ON DOGERR(IdDog);
    And now the query:
    SELECT D.IdDog, D.SfPdg, D.IdVpl, D.SfVpGot, D.SfZrr, T.IdVpl AS IdVplJoin, T.SfVpGot AS SfVpGotJoin, T.SfZrr AS SfZrrJoin
    FROM DOGERR D
    LEFT OUTER JOIN (SELECT * FROM DOGERR WHERE SfPdg = 'S' OR SfPdg = 'S') T ON
    T.IdVpl = D.IdVpl AND T.SfVpGot = D.SfVpGot AND T.SfZrr = D.SfZrr
    WHERE
    D.IdDog = 3
    AND D.SfVpGot = 2
    AND D.SfZrr = 'C';
    This query should (by my understanding) return only one row in wich the joined subquery columns should be NULL. And indeed query returns only one row on Oracle Database 10g Release 10.2.0.1.0 - Production and on Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production:
    IDDOG = 3, SFPDG = "$", IDVPL = 1, SFVPGOT = 2, SFZRR = "C", IDVPLJOIN = NULL, SFVPGOTJOIN = NULL, SFZRRJOIN = NULL
    But on Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - 64bit Production it returns TWO rows:
    IDDOG = 3, SFPDG = "$", IDVPL = 1, SFVPGOT = 2, SFZRR = "C", IDVPLJOIN = 1, SFVPGOTJOIN = 1, SFZRRJOIN = "7"
    IDDOG = 3, SFPDG = "$", IDVPL = 1, SFVPGOT = 2, SFZRR = "C", IDVPLJOIN = 1, SFVPGOTJOIN = 1, SFZRRJOIN = "7"
    And now the interesting part: any of the following modified versions of query works even on Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - 64bit Production, although modifications should not modify the result set:
    -- Removed unnecessary WHERE conditions
    SELECT D.IdDog, D.SfPdg, D.IdVpl, D.SfVpGot, D.SfZrr, T.IdVpl AS IdVplJoin, T.SfVpGot AS SfVpGotJoin, T.SfZrr AS SfZrrJoin
    FROM DOGERR D
    LEFT OUTER JOIN (SELECT * FROM DOGERR WHERE SfPdg = 'S' OR SfPdg = 'S') T ON
    T.IdVpl = D.IdVpl AND T.SfVpGot = D.SfVpGot AND T.SfZrr = D.SfZrr
    WHERE
    D.IdDog = 3;
    -- Removed unnecessary OR condition in subquery
    SELECT D.IdDog, D.SfPdg, D.IdVpl, D.SfVpGot, D.SfZrr, T.IdVpl AS IdVplJoin, T.SfVpGot AS SfVpGotJoin, T.SfZrr AS SfZrrJoin
    FROM DOGERR D
    LEFT OUTER JOIN (SELECT * FROM DOGERR WHERE SfPdg = 'S') T ON
    T.IdVpl = D.IdVpl AND T.SfVpGot = D.SfVpGot AND T.SfZrr = D.SfZrr
    WHERE
    D.IdDog = 3
    AND D.SfVpGot = 2
    AND D.SfZrr = 'C';
    -- Removed columns from joined subquery from SELECT part
    SELECT D.IdDog, D.SfPdg, D.IdVpl, D.SfVpGot, D.SfZrr, T.IdVpl AS IdVplJoin, T.SfVpGot AS SfVpGotJoin
    FROM DOGERR D
    LEFT OUTER JOIN (SELECT * FROM DOGERR WHERE SfPdg = 'S' OR SfPdg = 'S') T ON
    T.IdVpl = D.IdVpl AND T.SfVpGot = D.SfVpGot AND T.SfZrr = D.SfZrr
    WHERE
    D.IdDog = 3
    AND D.SfVpGot = 2
    AND D.SfZrr = 'C';
    NOTE: the query itself is a little stupid but this is just to demonstrate the problem. We have faced this problem at a customer with our real-world query.
    So, my question is: why different results ?
    Thanks.
    David

    hi,
    welcome to the forum,
    don't have a solution, but I thought I'd let you know that the first SQL statement only returns 1 row on 10gR2
    SQL> SELECT D.IdDog, D.SfPdg, D.IdVpl, D.SfVpGot, D.SfZrr, T.IdVpl AS IdVplJoin, T.SfVpGot AS SfVpGo
    tJoin, T.SfZrr AS SfZrrJoin
      2  FROM DOGERR D
      3  LEFT OUTER JOIN (SELECT * FROM DOGERR WHERE SfPdg = 'S' OR SfPdg = 'S') T ON
      4  T.IdVpl = D.IdVpl AND T.SfVpGot = D.SfVpGot AND T.SfZrr = D.SfZrr
      5  WHERE
      6  D.IdDog = 3
      7  AND D.SfVpGot = 2
      8  AND D.SfZrr = 'C';
         IDDOG S      IDVPL    SFVPGOT S  IDVPLJOIN SFVPGOTJOIN S
             3 $          1          2 C
    SQL> select * from v$version;
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
    PL/SQL Release 10.2.0.4.0 - Production
    CORE    10.2.0.4.0      Production
    TNS for Solaris: Version 10.2.0.4.0 - Production
    NLSRTL Version 10.2.0.4.0 - Production

  • SQL query return wrong Windows version

    when excuting   'select @@VERSION' returns wrong Windows version. Why?

    when excuting   'select @@VERSION' returns wrong Windows version. Why?
    SELECT @@VERSION will return SQLServer version and not windows version
    Even in case of sql, if you're seeing a different version from what your management studio suggests, then it may be that you're SSMS (client tool) is of another later version whereas the server instance which you're actually connecting to may
    be of different (earlier) version.
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • Query giving wrong results

    Below is the query thats giving me wrong results ...can anyone help me figure where i am going wrong :(
    SQL> select count(*) from t where source='LP1.1';
      COUNT(*)
            69
    SQL> select count(*) from tblspring where line_a='LP1.1';
      COUNT(*)
           233now when i join these two table ...the total counts exceeds the expected records that i want
    SQL> select count(*) from t , tblspring where t.source=tblspring.line_a and t.source='LP1.1';
      COUNT(*)
         16077

    the thing is i want to filter only those records from table t where the column named  - source is equal to the column named line_a from table tblspring from the query in table t i get 69 records ....
    now when i match the it table tblspring with the condition
    i want the number of records should be less than or equal to 69 but not more than 69
    Edited by: Suhail Faraaz on Mar 5, 2011 7:31 AM

  • Puzzle why query returned wrong value for last record in update.

    Hi all,
    10.2.0.4, Windows 32 bit.
    Apply 15% dis.count to related 5 items ( total amount 522 ) sorted by lowest amount first (amount = 1).
    Last record ( amount = 200 ) will be the total dis.count amount ( 78.3 ) less applied accumulated dis.count amount ( 48.50 ).
    Query runs fine without update clause but wrong result for last record with update.
    CREATE TABLE "T1"
        "ID"       NUMBER NOT NULL ENABLE,
        "ITEM_ID"  VARCHAR2(20 BYTE) NOT NULL ENABLE,
        "AMOUNT"   NUMBER(10,2) NOT NULL ENABLE,
        "dizcount" NUMBER(10,2)
    INSERT INTO T1 ( ID, ITEM_ID, AMOUNT, dizcount )  VALUES ( 65, '101', 1, NULL ) ;
    INSERT INTO T1 ( ID, ITEM_ID, AMOUNT, dizcount )  VALUES ( 65, '102', 1, NULL ) ;
    INSERT INTO T1 ( ID, ITEM_ID, AMOUNT, dizcount )  VALUES ( 65, '201', 200, NULL ) ;
    INSERT INTO T1 ( ID, ITEM_ID, AMOUNT, dizcount )  VALUES ( 65, '215', 155, NULL ) ;
    INSERT INTO T1 ( ID, ITEM_ID, AMOUNT, dizcount )  VALUES ( 65, '111', 165, NULL ) ;
    UPDATE t1 a
    SET a.dizcount =
      (SELECT
        CASE
          WHEN rec_count = row_count
          THEN (78.3 - NVL(lag(temp_total,1) over ( order by rec_count) ,0))-- 78.3 is total dizcount amount from 522 * .15
          ELSE disc_amt
        END amt
      FROM
        (SELECT id,
          item_id,
          disc_amt,
          rec_count,
          row_count,
          CASE
            WHEN rec_count != row_count -- accumulate dizcount amount except for last record
            THEN SUM(disc_amt) over (order by rec_count)
            ELSE 0
          END temp_total
        FROM
          (SELECT ID ,
            item_id,
            amount amt,
            ROUND(amount * .15,1) disc_amt, -- dizcount is 15%
            row_number () over (order by amount) rec_count,
            COUNT ( *) over () row_count
          FROM t1
          WHERE ID = 65
        GROUP BY id,
          item_id,
          disc_amt,
          rec_count,
          row_count
        )b
      WHERE a.item_id = b.item_id
      );Regards
    Zack
    Edited by: Zack.L on Jul 26, 2010 1:26 AM

    Zack.L wrote:
    Query runs fine without update clause but wrong result for last record with update.Not sure why but looks like another case in favour of MERGE.
    MERGE INTO T1
    using (SELECT id, item_id,
        CASE
          WHEN rec_count = row_count
          THEN (78.3 - NVL(lag(temp_total,1) over ( order by rec_count) ,0))-- 78.3 is total dizcount amount from 522 * .15
          ELSE disc_amt
        END amt
      FROM
        (SELECT id,
          item_id,
          disc_amt,
          rec_count,
          row_count,
          CASE
            WHEN rec_count != row_count -- accumulate dizcount amount except for last record
            THEN SUM(disc_amt) over (order by rec_count)
            ELSE 0
          END temp_total
        FROM
          (SELECT ID ,
            item_id,
            amount amt,
            ROUND(amount * .15,1) disc_amt, -- dizcount is 15%
            row_number () over (order by amount) rec_count,
            COUNT ( *) over () row_count
          FROM t1
          WHERE ID = 65
        GROUP BY id,
          item_id,
          disc_amt,
          rec_count,
          row_count
        ))b
    on (t1.id = b.id and t1.item_id = b.item_id)
    when matched then update set dizcount = b.amt ;This worked for me. I tested on 11.2 but should work on 10.2.0.4
    SQL> select * from t1 order by amount ;
            ID ITEM_ID                  AMOUNT   DIZCOUNT
            65 101                           1         .2
            65 102                           1         .2
            65 215                         155       23.3
            65 111                         165       24.8
            65 201                         200       29.8p.s. BTW, not sure if you want the column names in different cases, but your script, as it is, gave me an error (on 11.2)

  • Query returning No result

    Hi,
    I installed Oracle Express Edition 10g in my system.
    I ran a very simple query:
    Select * from person where status = 100
    where status is NUMBER(9) NOT NULL but it does not returning any result.
    Any Idea? Is this because of Express Edition version?
    Thank You.

    You've been asked twice to show us a copy/paste of a query which you've not done.
    Fire up SQLPlus, run the command asked of you, and copy and then paste the results into a post (enclosing it in the tags to preserve formatting).
    It's much easier to help you when you try and help us by following along with suggestions.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Spotlight returns wrong results

    After installing Yosemite on my MacBook Pro, I tried to use Spotlight on some simple searches, with startling results. For example, I looked for Spotlight help...and a Word for Mac file opened. I recognize that Spotlight scours my Mac for material, but I do not understand why it would open a file that has nothing to do with the search terms.
    Can anyone hazard a guess about what may be happening?

    Did it and it worked to add _spotlight to the ACLs but Spotlight still return blank results on AFP clients...
    Do you know what should be the permissions on the .spotlight-V100 folder?
    Spotlight works on the servers so the index is fine. It's the AFP clients that can't read it properly or don't get all the data from it.

Maybe you are looking for