Query with Top N Condition (Result Row)

Hi,
I made a query with an active top n condition. The query has 2 Keyfigures and 1 formula
Gross-sales acutal | Gross-sales previous year | Previous Year %
So that to result line is correct, I had to say "Calculate result as summation" for the keyfigures
gross sales actual and gross sales previous year. That works.
I have the problem with my formula. the formular for previous year % is defined as follows:
gross sales actual %A gross sales previous year
Example Top 3 Customer
                    gross sales actual          gross sales prev. year         prev. year %
Cust 1          100                                   80                                       125 %
Cust 2          90                                     45                                        200 %
Cust 3           80                                    60                                        133 %
Result          270                                   185                                       142.8 % ( 350 * 100 / 245 )
The result of 142 % is the correct result without the condition top 3. with the top 3 condition
the result should be 270 * 100 / 185 = 145.9 %
Additional customer without top 3 condition
Cust 4          50                                       40                                        125 %
Cust 5          30                                        20                                        150 %
It shows the correct result for each single line. The result in the result row is wrong. it is calculated
without taking the active condition. the formular calculates
with the total gross sales actual and the total of gross sales prev. year.
is there any solution the achieve the correct % in the result row?
thanks for your help.
Pascal

Pascal,this is a known behavior with conditions.When you apply condition it just hide the extra rows and it does not impact the result row.So your result row actually shows the value irrespective of the condition you apply.
Now with the help of local functions like calculate result as summation you can show the correct sum after applying the condition but when you try to use that result in some calculation then it takes the original value thereby discarding the calculated value.
Same is happening in your case as well.Its taking the original value i.e 350 and not the calculated sum after condition i.e 270.
Hope this helps.
Regards,
AL

Similar Messages

  • Query designer and Standard deviation result rows

    Hello everyone,
    Here is my problem.
    I have a key figure for which I do not want any decimals. So in the Number Format : Number of Decimal Places = 0.
    I thought the result rows would follow the same rules by not displaying any decimals.
    But using the Calculate Result as ... "Standard Deviation", even though my key figure is define with no decimals, the result row displays 5 decimals anyway ! 
    Why? and is there any way I can suppress the decimals of my results rows with a Standard Deviation 
    Thx
    JBF
    Edited by: Jean-Baptiste Faubert on Jan 16, 2008 2:56 PM

    Hello Jean,
    First I would try to unmark flag 'Use default Settings' below Number of Decimal Places in Query Designer.
    If this doesn't help you could set Decimal Places in the Provider specific Properties in Key Figure of the MultiProvider used from 'Not defined' to 0.
    Also you could change the number of decimals in InfoObject maintainance of used Key Figure (in RSA1).
    But then you have to check other queries where this Key Figure is used.
    Kind regards
    Klaus

  • Dynamic select query with dynamic where condition

    Hi all,
    I want to use the dynamic select query with dynamic where condition. For that I used the below code but I am getting dump when using this code.
    Please advice, if there is any other way to achieve this requirement.
    Thanks,
    Sanket Sethi
    Code***************
    PARAMETERS: p_tabnam      TYPE tabname,
                p_selfl1      TYPE edpline,
                p_value       TYPE edpline,
                p_where1      TYPE edpline .
    DATA: lt_where    TYPE TABLE OF edpline,
          lt_sel_list TYPE TABLE OF edpline,
          l_wa_name   TYPE string,
          ls_where    TYPE edpline,
          l_having    TYPE string,
          dref        TYPE REF TO data,
          itab_type   TYPE REF TO cl_abap_tabledescr,
          struct_type TYPE REF TO cl_abap_structdescr,
          elem_type   TYPE REF TO cl_abap_elemdescr,
          comp_tab    TYPE cl_abap_structdescr=>component_table,
          comp_fld    TYPE cl_abap_structdescr=>component.
    TYPES: f_count TYPE i.
    FIELD-SYMBOLS : <lt_outtab> TYPE ANY TABLE,
    *                <ls_outtab> TYPE ANY,
                    <l_fld> TYPE ANY.
    struct_type ?= cl_abap_typedescr=>describe_by_name( p_tabnam ).
    elem_type   ?= cl_abap_elemdescr=>describe_by_name( 'F_COUNT' ).
    comp_tab = struct_type->get_components( ).
    comp_fld-name = 'F_COUNT'.
    comp_fld-type = elem_type.
    APPEND comp_fld TO comp_tab.
    struct_type = cl_abap_structdescr=>create( comp_tab ).
    itab_type   = cl_abap_tabledescr=>create( struct_type ).
    l_wa_name = 'l_WA'.
    CREATE DATA dref TYPE HANDLE itab_type.
    ASSIGN dref->* TO <lt_outtab>.
    *CREATE DATA dref TYPE HANDLE struct_type.
    *ASSIGN dref->* TO <ls_outtab>.
    * Creation of the selection fields
    APPEND p_selfl1 TO lt_sel_list.
    APPEND 'COUNT(*) AS F_COUNT' TO lt_sel_list.
    ** Creation of the "where" clause
    *CONCATENATE p_selfl1 '= '' p_value ''.'
    *            INTO ls_where
    *            SEPARATED BY space.
    *APPEND ls_where TO lt_where.
    * Creation of the "where" clause
    APPEND p_where1 TO lt_where.
    * Creation of the "having" clause
    l_having = 'count(*) >= 1'.
    * THE dynamic select
    SELECT          (lt_sel_list)
           FROM     (p_tabnam)
           INTO CORRESPONDING FIELDS OF TABLE <lt_outtab>.
    *       WHERE    (lt_where).

    Hi Sanket,
    The above given logic of mine works for you, put the code in the If condition and try-
    just like below:
    IF NOT P_EBELN IS INITIAL.
    lt_where = '& = ''&'' '.
    REPLACE '&' WITH p_ebeln INTO lt_where.
    REPLACE '&' WITH field_value INTO lt_where.
    SELECT (lt_sel_list) INTO CORRESPONDING FIELDS OF TABLE <lt_outtab>
    FROM (p_tabnam)
    WHERE (lt_where).
    ENDIF.
    thanks\
    Mahesh

  • Incorrect query result with Top N condition and two structures

    Hi,
    I have created a query on a FI-GL infocube with the characteristic 0BUS_AREA in rows and two structures in columns. The first structure has two items / selections (each item is a selection of several GL accounts). The second structure has two items (the first one contains the key figure 0BALANCE for the current period and the second item is a formula that calculates the absolute value of the first item. The first item is hidden). The (simplified) result looks like this (sorry, not very pretty!):
    Business Area Clients Clients fae
    Business Area1 10 15
    Business Area2 20 7
    Business Area 3 15 8
    Overall result 45 30
    I then added one condition using the Top N operator. The condition is defined for all the elements of the structures. When I execute the query, I sometimes obtained an incorrect number of Top N records selected. The problem seems to occur when N is greater than the number of available Business Areas for an element of the structure.
    For example, if N = 8 and data only exists for 5 Business Areas for the structure element Clients, I may end up with 10 Business Areas for the second structure element Clients fae when I only expect 9 (i.e. the top 8 Clients fae + 1 of the Top 8 Clients for which there is no data under Clients fae).
    Has anybody encoutered that kind of problem ?
    Many thanks.
    François.

    Pascal,this is a known behavior with conditions.When you apply condition it just hide the extra rows and it does not impact the result row.So your result row actually shows the value irrespective of the condition you apply.
    Now with the help of local functions like calculate result as summation you can show the correct sum after applying the condition but when you try to use that result in some calculation then it takes the original value thereby discarding the calculated value.
    Same is happening in your case as well.Its taking the original value i.e 350 and not the calculated sum after condition i.e 270.
    Hope this helps.
    Regards,
    AL

  • Create  query with top 5 and rest

    Hi,i want to have a query that gives a list in the following format
    customer  - value of orders
    #1            -  20.500
    #2            -  20.100
    #3            -  16.000
    #4            -  15.000
    #5            -  14.000
    Rest         -  49.600
    how can i achieve that in a convenient way  - filters,conditions,exceptions,properties etc - all those new stuff?
    (i am new to BI,so excuse my beginners question,please)

    Hi,i am not sure if it is possible to diaply Value of Rest with standard functionality.Instead you can display Overall result.
    Create a condition TOP N and speify the number as 5. and make sure Suppress Result rows of Customer is set to 'never'.So you will get displayed Top 5 Customers and Overall result.
    if you are saving the result as WorkBook,then add one more Row after Query result to display result  with the Excel formula Overall Result-Top 5.Save the Workbook.

  • Hierarchy query with dynamic start condition

    Hi,
    I have a table that stores hierarchical items (foohierarchy) and another one storing users and such items (useritems). Unfortunately the latter one is not consistent and misses some entries. I would like to fix that using pure sql. Fixing here means that a user that possesses a certain child element should also have parents of that child. There are a couple of obstacles here though. First the hierarchy table does not explicitly state which elements are top level elements. I am trying to fix that by emulating a proper structure and named that fixedhierarchy. A select statement that returns all intended user/item relationships would be nice.
    Here some visualization and sample data, the sample data follows the pattern that each item uses its level as its suffix, but this shouldn't be exploited in the statement:
    asci art:
    -- A1 (peter,paul)
    --   \_ B2
    --   \_ C2
    --        \_D3 (thomas)
    --            \_X4
    -- E1
    --   \_F2
    -- G1
    --   \_H2 (heidi)sample data
    drop table foohierarchy;
    drop table useritems;
    create table foohierarchy (
    child_item varchar2(30),
    parent_item varchar2(30));
    insert into foohierarchy values ('B2','A1');
    insert into foohierarchy values ('C2','A1');
    insert into foohierarchy values ('D3','C2');
    insert into foohierarchy values ('X4','D3');
    insert into foohierarchy values ('F2','E1');
    insert into foohierarchy values ('H2','G1');
    create table useritems (
    username varchar2 (40),
    item varchar2(30)
    insert into useritems values ('peter','A1');
    insert into useritems values ('paul','A1');
    insert into useritems values ('thomas','D3');
    insert into useritems values ('heidi','H2');
    commit;my attempt at fixing the hierarchy table
    with fixedhierarchy as
    (select parent_item,child_item from foohierarchy
    union all
    select distinct null parent_item,parent_item child_item from foohierarchy where parent_item not in (select child_item from foohierarchy))
    select * from fixedhierarchy;What the select should return:
    'peter'|'A1'
    'paul'|'A1'
    'thomas'|'A1'
    'thomas'|'C2'
    'thomas'|'D3'
    'heidi'|'G1'
    'heidi'|'H2'

    Hi,
    Thanks for posting the CREATE TABLE and INSERT statments; that's very helpful! Don't forget to mention what version of Oracle you're using. That's especially important with hierachies; every version since Oracle 7 has had significant improvements in how to handle them.
    I'm a little comfused as to what you want. Are you trying to permanently change the tables? If so, show what the changed table(s) should look like when the job is finished. Post the output you would want to see from "SELECT * FROM useritems;" or "SELECT * FROM foohierarchy;", or, if you want to change both tables, from both.
    It looks like you have two separate problems:
    (1) Changing foohierarchy, so that every item appears once as a child_id. That means adding rows with NULL parent_item for all the roots ('A1', 'E1' and 'G1'). The query you posted seems directed toward this.
    (2) Denormalizing useritems, so that when a username is linked to an item, the username is linked to all that item's ancestors, too. The results you posted seem to be what you want useritems to look like after this is done.
    Here's how to do those things:
    <h4>(1) Changing foohierarchy</h4>
    The query you posted looks good. Do you see anything wrong with it? You can use that query (or something very close to it) in an INSERT or MERGE statement.
    If you just want to add some new rows to foohierarchy, then you don't need the UNION: just the second branch of it. If you're cvertain that none of those rows already exist in foohierarchy, then
    INSERT INTO foohierarchy (parent_item,      child_item)
         SELECT DISTINCT   NULL,          childitem
         FROM     foohierarchy
         WHERE     parent_item     NOT IN (
                             SELECT      child_item
                             FROM     foohierarchy
    ;If some of the roots might already be in foohierarchy correctly, then you'll want a something in the WHERE clause to make sure you don';t add a duplicate. A MERGE statment might do this better than INSERT.
    <h4>(2) Denormalizing useritems</h4>
    This adds new rows to useritems, to make it look like what you posted:
    ERGE INTO     useritems     dst
    USING (
         WITH     all_ancestors     AS
              SELECT     CONNECT_BY_ROOT child_item     AS descendant
              ,     parent_item               AS ancestor
              FROM     foohierarchy
              START WITH     child_item   IN     (
                                       SELECT     item
                                       FROM     useritems
              CONNECT BY     child_item   = PRIOR parent_item
         SELECT DISTINCT
              u.username
         ,     a.ancestor
         FROM     all_ancestors     a
         JOIN     useritems     u  ON     a.descendant     = u.item
          )                    src
    ON     (     src.username     = dst.username
         AND     src.ancestor     = dst.item
    WHEN NOT MATCHED THEN
         INSERT     (dst.username,     dst.item)
         VALUES     (src.username,     src.ancestor)
    ;After doing this, "SELECT * FROM useritems;" will produce this output:
    USERNAME   ITEM
    paul       A1
    peter      A1
    thomas     A1
    thomas     C2
    thomas     D3
    heidi      G1
    heidi      H2Here's how it works:
    Sub-query all_ancestors is a bottom-up CONNECT BY query, linking each node in useritems with all of its ancestors. CONNECT BY queries are often slow under the best circumstances; doing a join in a CONNECT BY query makes it even slower. It's more efficient to do the CONNECT BY query first, in a sub-query, and then join tht result set to other tables, as I did in src.

  • SQL query with parameter returns empty result set, please help !!!

    Hi there,
    When I use the following query :
    <sql:query var="beroepsthemas" >
    select *
    from beroepsthemas
    where beroepsthemaid = ?
    <sql:param value="12"/>
    </sql:query>
    When I want to browse the result set with :
    <c:forEach items="${beroepsthemas.rows}" var="rij">
    it shows no records. But it must return at least one.
    All my jsp pages with sql queries and parameters have the same problem.
    This is all on my test environment. I'm using Ubuntu 5.10, Netbeans5.0, JDK 1.5_06, application runs in Bundeled Tomcat 5.5.9, MySQL 4.1.12, mysql-connector3.1.6
    When the same code is run on the live environment, it works just fine.
    The difference is :
    Mysql 4.1.10a, tomcat5.5.9, mysql-connector3.1.6
    What can there be wrong !!

    When the same code is run on the live environment, it
    works just fine.
    The difference is :
    Mysql 4.1.10a, tomcat5.5.9, mysql-connector3.1.6
    I didn't catch this. I think you may need to update the database driver.

  • Web Template with document icon in result row

    Hi All,
    I have a web template created in WAD 7.0.
    It has Analysis item with a Query as dataprovider.I have checked the "Document Icons for Data" to On in the cell content section of Analysis Item.
    In query property also,Document link for infoprovider option is checked.
    It is displaying the document icon in data cells correctly wherever comment is entered.But it also displays document icon in the result row cells.
    I do not want to display the document icon in the result row cells.
    Please help in this regard.
    Thanks.

    Have you considered creating and using query views?

  • 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                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Report on BEx query with 2 structures (one in rows and one in columns)

    Hi, experts! I have to make Crystall report on BEx query with 2 structures, one in columns (with KF's), and one in rows. Is it possible to create such report? Because when I create such report, I cant see fields in structures, only characteristics fields.
    Ok, I found samr problem in another thread. Sorry.
    Edited by: Mikhail Sychev on Dec 5, 2009 9:53 PM

    Hey Flora,
    Happy to hear that its working now.
    Answering your question, again its upto the connection and report format you are using. Based on your question i hope you your report output should be like this.
    You cannot map to two labels for the series, again this report format is possible only in cross tab through Webi. I would suggest you to concatenate the material and month in a dimension in webi like below.
    I have done the concatenation in excel level, i would suggest you to do that in webi. Try to reduce the formula as much in excel.
    or
    If you are using Query browser connection, then i would suggest you to create a separate report which will display the actual vs plan material wise, here you need to pass the material as a prompt.
    Hope this helps in clear, please revert me for any clarification.

  • CAML Query with 10 AND conditions

    Hello,
    I need some help with a CAML query. This particular query needs to have 10 AND conditions. Quite frankly, with all the nesting it is driving me a little nuts:
    What I have is:
    <Query>
    <Where>
    <And>
    <And>
    <And>
    <And>
    <And>
    <And>
    <And>
    <And>
    <And>
    <Eq><FieldRef Name='Column1' LookupId='TRUE' /><Value Type='Text'>10341</Value></Eq>
    <Eq><FieldRef Name='Column2' LookupId='TRUE' /><Value Type='Text'>9539</Value></Eq>
    </And>
    <Eq><FieldRef Name='Column3' LookupId='TRUE' /><Value Type='Text'>183</Value></Eq>
    </And>
    <Eq><FieldRef Name='Column4' LookupId='TRUE' /><Value Type='Text'>35</Value></Eq>
    </And>
    <IsNull><FieldRef Name='Column5' /></IsNull>
    </And>
    <Eq><FieldRef Name='Column6' LookupId='TRUE' /><Value Type='Text'>4387</Value></Eq>
    </And>
    <Eq><FieldRef Name='Column7' LookupId='TRUE' /><Value Type='Text'>4204</Value></Eq>
    </And>
    <Eq><FieldRef Name='Column8' LookupId='TRUE' /><Value Type='Text'>36</Value></Eq>
    </And>
    <Eq><FieldRef Name='Column9' LookupId='TRUE' /><Value Type='Text'>213</Value></Eq>
    </And>
    <IsNull><FieldRef Name='Column10' /></IsNull>
    </And>
    </Where>
    </Query>
    I have added this into my ItemAdding Event Receiver as it will basically do a check for duplicate items based on the 10 columns. 
    If anyone can help guide me in this, it would be much appreciated. I have been using a CAML Query Builder to help.

    http://webcache.googleusercontent.com/search?q=cache:xji7jOxa5_EJ:aasai-sharepoint.blogspot.com/2013/02/caml-query-with-multiple-conditions.html+&cd=3&hl=en&ct=clnk&gl=in
    http://stackoverflow.com/questions/6203821/caml-query-with-nested-ands-and-ors-for-multiple-fields
    Since you are not allowed to put more than two conditions in one condition group (And | Or) you have to create an extra nested group (MSDN). The expression
    A AND B AND C looks like this:
    <And>
    A
    <And>
    B
    C
    </And>
    </And>
    Your SQL like sample translated to CAML (hopefully with matching XML tags ;) ):
    <Where>
    <And>
    <Or>
    <Eq>
    <FieldRef Name='FirstName' />
    <Value Type='Text'>John</Value>
    </Eq>
    <Or>
    <Eq>
    <FieldRef Name='LastName' />
    <Value Type='Text'>John</Value>
    </Eq>
    <Eq>
    <FieldRef Name='Profile' />
    <Value Type='Text'>John</Value>
    </Eq>
    </Or>
    </Or>
    <And>
    <Or>
    <Eq>
    <FieldRef Name='FirstName' />
    <Value Type='Text'>Doe</Value>
    </Eq>
    <Or>
    <Eq>
    <FieldRef Name='LastName' />
    <Value Type='Text'>Doe</Value>
    </Eq>
    <Eq>
    <FieldRef Name='Profile' />
    <Value Type='Text'>Doe</Value>
    </Eq>
    </Or>
    If this helped you resolve your issue, please mark it Answered

  • SQL query with lots of conditions issue..

    Working on A large query that hits a large DB of parts.
    The table I am given these parts are broken up into 4 fields.
    Section,Groupid,Subgroupid,Component
    When I hit this table, i am given a list of all the possible combo's of the 4 fields that can be used for that lookup at that time.
    The problem is its SLOW when this list is pretty big.. a lot of times, over 200 rows of combos... so end up with something like below,
    but stripped down for explaining...
    So a generic version the query..
    Select * from PartTable where
    ( (section='blah1') and (groupid='blah2') and (subgroupid='blah3') and (component='blah4') ) or
    ( (section='blah5') and (groupid='blah6') and (subgroupid='blah7') and (component='blah8') ) or
    ( (section='blah9') and (groupid='blah10') and (subgroupid='blah11') and (component='blah12') ) or
    ( (section='blah250') and (groupid='blah251') and (subgroupid='blah252') and (component='blah253') )I have changed it to a deal where I have a subquery and do a case statement to query a subquery, but the problem I run into that
    is, is that 10g only allows so many. I can get around this by when i generate the query, to just make multiple case statements and then
    modify my where statement.. but seems sloppy.. but "Works" .. using the OR statement deal, it can take near 30 seconds... with the
    sloppy looking multiple case statement field deal, it takes 1.6 seconds..

    870023 wrote:
    Try creating Index on these columns. Will help in CPU cost.That is one of the most useless pieces of advice I have ever seen.
    CPU cost does not necessarily reflect performance. Creating too many indexes can also slow down performance. The first way of tackling a performance issue is to find out what the cause is, before trying to figure out the best way to fix it.
    {message:id=9360003}

  • Single SQl Query with different where conditions

    Experts,
    I have a requirement to design a report. Here are the details
    I have Report table layout
    Profit center Gross sales (This Year) Gross Sales (Last Year) % change Year of Year
    The Report has a selection of entering the Start Date.
    I have a single table in oracle which has profit center and Gross Sales Values on daily basis.
    I want to write a single sql query to calculate both Gross Sales current year and Gross Sales Last Year. I can calculate Gross Sales Current Year by putting the where condition for start date = Current Year Date which i pass through report. I want to calculate the Gross Sales Last Year in the Same query by putting the different where condition i.e start date = Last Year date based on the date input.
    I dont know how to put two where conditions in single query for two different columns.
    Any help will be appreciated.
    Thanks in advance
    Regards
    Santosh

    instead of changing your where clause couldn't you just determine the yearly totals from your table and then use the lag statement to get last years total?
    something like this?
    I just made up 10,000 days worth of sales and called it fake table it is supposed to represent a variant of the table you were describing as your base table.
    with fake_table as
    ( select trunc(sysdate + level) the_day,
    level daily_gross_sales
    from dual
    connect by level < 10001
    select yr, year_gross_sale, lag(year_gross_sale) over (order by yr) prev_year_gross_sale,
    (year_gross_sale - lag(year_gross_sale) over (order by yr))/year_gross_sale * 100 percent_change
    from
    (select distinct yr, year_gross_sale from
    select the_day,
    daily_gross_sales,
    extract(year from the_day) yr,
    extract(year from add_months(the_day,12)) next_yr,
    sum(daily_gross_sales) over (partition by extract(year from the_day)) year_gross_sale
    from fake_table
    order by yr
    )

  • Enhance a SQL query with update of millions of rows

    Hi ,
    I have this query developed to updated around 200 million of rows on my production , I did my best but please need your recommendations\concerns to make it more enhanced
    DECLARE @ORIGINAL_ID AS BIGINT
    SELECT FID001 INTO #Temp001_
    FROM INBA004 WHERE RS_DATE>='1999-01-01'
    AND RS_DATE<'2014-01-01' AND CLR_f1st='SSLM'
    and FID001 >=12345671
    WHILE (SELECT COUNT(*) FROM #Temp001_ ) <>0
    BEGIN
    SELECT TOP 1 @ORIGINAL_ID=FID001 FROM #Temp001_ ORDER BY FID001
    PRINT CAST (@ORIGINAL_ID AS VARCHAR(100))+' STARTED'
    SELECT DISTINCT FID001
    INTO #OUT_FID001
    FROM OUTTR009 WHERE TRANSACTION_ID IN (SELECT TRANSACTION_ID FROM
    INTR00100 WHERE FID001 = @ORIGINAL_ID)
    UPDATE A SET RCV_Date=B.TIME_STAMP
    FROM OUTTR009 A INNER JOIN INTR00100 B
    ON A.TRANSACTION_ID=B.TRANSACTION_ID
    WHERE A.FID001 IN (SELECT FID001 FROM #OUT_FID001)
    AND B.FID001=@ORIGINAL_ID
    UPDATE A SET Sending_Date=B.TIME_STAMP
    FROM INTR00100 A INNER JOIN OUTTR009 B
    ON A.TRANSACTION_ID=B.TRANSACTION_ID
    WHERE A.FID001=@ORIGINAL_ID
    AND B.FID001 IN (SELECT FID001 FROM #OUT_FID001)
    DELETE FROM #Temp001_ WHERE FID001=@ORIGINAL_ID
    DROP TABLE #OUT_FID001
    PRINT CAST (@ORIGINAL_ID AS VARCHAR(100))+' FINISHED'
    END

    DECLARE @x INT
    SET @x = 1
    WHILE @x < 44,000,000  -- Set appropriately
    BEGIN
        UPDATE Table SET a = c+d where ID BETWEEN @x AND @x + 10000
        SET @x = @x + 10000
    END
    Make sure that ID column has a CI on.
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • Select query with optional where condition

    Hi,
    Can Anybody help me out in the following problem?
    I have the following query in a procedure.
    SELECT replace(shipper_name,'\',' ') as shipper,
    sum(teus / cntSailings) as teus
    FROM VW_CONTRIBUTION,
    VW_TOTAL_SAILINGS
    WHERE VW_CONTRIBUTION.dir = VW_TOTAL_SAILINGS.DIR
    AND VW_CONTRIBUTION.line = VW_TOTAL_SAILINGS.LINE
    AND VW_CONTRIBUTION.accounting_month = VW_TOTAL_SAILINGS.ACCOUNTING_MONTH
    AND VW_CONTRIBUTION.accounting_year = VW_TOTAL_SAILINGS.ACCOUNTING_YEAR
    AND VW_CONTRIBUTION.Principal = arg_principal
    AND VW_CONTRIBUTION.Dir = arg_direction
    AND VW_CONTRIBUTION.line in ( arg_service )
    AND VW_CONTRIBUTION.POL_country = arg_pol
    AND VW_CONTRIBUTION.POd_country = arg_pod
    AND VW_CONTRIBUTION.salesOffice = arg_SalesOffice
    AND VW_CONTRIBUTION.salesregion = arg_SalesRegion
    AND VW_CONTRIBUTION.cargo_type = arg_txtCargoType
    AND VW_CONTRIBUTION.eqgroup = arg_ContType
    AND VW_CONTRIBUTION.eq_size = arg_txtSize
    AND VW_CONTRIBUTION.acct_date between arg_from_date and arg_end_date
    GROUP BY shipper_name
    ORDER BY teus desc;
    Here some of the arguments are optional(Eg : VW_CONTRIBUTION.salesOffice, AND VW_CONTRIBUTION.eqgroup etc. ) and the values can be null. When they are null, I want them to be excluded from the where condition. Can anybody suggest me a solution for this?
    Thanks,
    Shalet.

    I guess i misunderstood your original question.
    The clause
    AND (VW_CONTRIBUTION.salesOffice = arg_SalesOffice OR VW_CONTRIBUTION.salesOffice IS NOT NULL)
    will cause the where clause to evaluate to FALSE anytime salesOffice IS NULL so the record will be excluded.
    I thought you were asking how to not compare the value if the field contained a NULL.
    Glad you found what you wanted.

Maybe you are looking for

  • Free item and BAPI_PO_CREATE

    Hi experts, When creating a PO with BAPI_PO_CREATE I need to set the indicator "Free" (MEPO1211-UMSON) of the item. The question is, can I do it with this bapi? I can't find the field in the bapi. Thanks a lot

  • TEXT Mail line break issue in Email body

    Email content is breaking up when the preference is MAILTEXT. Please see the comments Line Break. Ex: Dear --Line Break PETER, Thank you for contacting XXXXX. The service request number 547631 has been created for the following issue: Testing Notific

  • Adobe Acrobat 6 and IMac 10.8.3

    I recently purchased an IMac and it doesn't seem to support my rather old Acrobat 6. Can I update Acrobat without having to purchase the full version again?

  • RVS4000 not Port forwarding

    I have  a new RVS4000 router, which is hosing a seagate GoFlec Home drive. Origianally my WRT54G router worked fine. I cannot get the UPnP to work. I have UPnP enabled. I have my goFlex Home to automatically configure router for portforwarding, ports

  • Ampersand in portal tools entitlements causing exception

    There appears to be a bug in the portal tools that ship with 4.0. If you have a portal page with an ampersand in the name, EBCC creates the XML that is loaded to the database correctly (with the &). But when you try to create an entitlement for this