TSQL - Dynamic Query Case statment update issue - to update table by left shifting the rows

Hi all
I need an help on my tsql query in 2000 to fix the case statement.
I have a table like shown below.
On this table where ever I see PortID as 101 and 105 I need to remove it and shift the rows from right to left.
ie on First row PortID1 is 101 so I need to remove it and replace it with PortId2 and similarly PortID2 replaced my PortID3 and so on.
ie like on excel if you delete cell we need to shift the rows to left .
I wrote an dynamic update statement i,m not sure on the assigning dynamic case statment.
CREATE TABLE [TravelRank]
[Destination] [varchar] (50) NULL,
[PortID1] [int] NULL ,
[Distance1] [int] NULL ,
[Rating1] [int] NULL ,
[PortID2] [int] NULL ,
[Distance2] [int] NULL ,
[Rating2] [int] NULL ,
[PortID3] [int] NULL ,
[Distance3] [int] NULL ,
[Rating3] [int] NULL ,
[PortID4] [int] NULL ,
[Distance4] [int] NULL ,
[Rating4] [int] NULL
INSERT into [TravelRank]
select 'Virgin Islands','101','10','5','102','20','5','103','31','5','109','41','5'
Union all
select 'Guinea','101','15','3','102','22','3','105','32','2','110','45','4'
Union all
select 'Benin ','102','12','4','106','28','4','104','33','3','109','48','2'
Union all
select 'Ecuador','102','18','5','101','29','5','108','34','1','111','45','5'
Union all
select 'Belarus ','103','17','4','105','24','4','108','45','4','112','46','3'
Union all
select 'Cook Islands','105','11','2','108','23','2','101','32','2','107','42','4'
Here is my code to fix
declare @SQL varchar(4000)
declare @left varchar(1)
declare @right varchar(1)
select @left = '1',@right = '2'
while @left < 4
begin
select @SQL = '
update t1.PortID' + @left + ' = t2.PortID' + @right + '
t1.Distance' + @left + ' = t2.Distance' + @right + '
t1.Rating' + @left + ' = t2.Rating' + @right + '
'case @left
when '1' then
' t1.PortID' + cast(cast(@left as int)+1 as varchar(1)) + ' = t2.PortID' + cast(cast(@right as int)+1 as varchar(1)) +'
t1.PortID' + cast(cast(@left as int)+2 as varchar(1)) + ' = t2.PortID' + cast(cast(@right as int)+2 as varchar(1)) +'
t1.PortID' + cast(cast(@left as int)+3 as varchar(1)) + ' = t2.PortID' + cast(cast(@right as int)+3 as varchar(1)) +'
t1.Distance' + cast(cast(@left as int)+1 as varchar(1)) + ' = t2.Distance' + cast(cast(@right as int)+1 as varchar(1)) +'
t1.Distance' + cast(cast(@left as int)+2 as varchar(1)) + ' = t2.Distance' + cast(cast(@right as int)+2 as varchar(1)) +'
t1.Distance' + cast(cast(@left as int)+3 as varchar(1)) + ' = t2.Distance' + cast(cast(@right as int)+3 as varchar(1)) +'
t1.Rating' + cast(cast(@left as int)+1 as varchar(1)) + ' = t2.Rating' + cast(cast(@right as int)+1 as varchar(1)) +'
t1.Rating' + cast(cast(@left as int)+2 as varchar(1)) + ' = t2.Rating' + cast(cast(@right as int)+2 as varchar(1)) +'
t1.Rating' + cast(cast(@left as int)+3 as varchar(1)) + ' = t2.Rating' + cast(cast(@right as int)+3 as varchar(1)) +'
' when '2' then
' t1.PortID' + cast(cast(@left as int)+1 as varchar(1)) + ' = t2.PortID' + cast(cast(@right as int)+1 as varchar(1)) +'
t1.PortID' + cast(cast(@left as int)+2 as varchar(1)) + ' = t2.PortID' + cast(cast(@right as int)+2 as varchar(1)) +'
t1.Distance' + cast(cast(@left as int)+1 as varchar(1)) + ' = t2.Distance' + cast(cast(@right as int)+1 as varchar(1)) +'
t1.Distance' + cast(cast(@left as int)+2 as varchar(1)) + ' = t2.Distance' + cast(cast(@right as int)+2 as varchar(1)) +'
t1.Rating' + cast(cast(@left as int)+1 as varchar(1)) + ' = t2.Rating' + cast(cast(@right as int)+1 as varchar(1)) +'
t1.Rating' + cast(cast(@left as int)+2 as varchar(1)) + ' = t2.Rating' + cast(cast(@right as int)+2 as varchar(1)) +'
' when '3' then
' t1.PortID' + cast(cast(@left as int)+1 as varchar(1)) + ' = t2.PortID' + cast(cast(@right as int)+1 as varchar(1)) +'
t1.Distance' + cast(cast(@left as int)+1 as varchar(1)) + ' = t2.Distance' + cast(cast(@right as int)+1 as varchar(1)) +'
t1.Rating' + cast(cast(@left as int)+1 as varchar(1)) + ' = t2.Rating' + cast(cast(@right as int)+1 as varchar(1)) +'
' when '3' then
' t1.PortID' + @left + ' = null '
t1.Distance' + @left + ' = null '
t1.Rating' + @left + ' = null '
else '' end'
from [TravelRank] t1
inner join [TravelRank] t2
on t1.destination = t2.destination
where t1.PortID1 = 101'
print @SQL
-- exec (@SQL)
select @left = cast(cast(@left as int) + 1 as varchar(1))
, @right = cast(cast(@right as int) + 1 as varchar(1))
end
Thanks a lot in advance.

declare @SQL varchar(4000)
declare @left varchar(1)
declare @right varchar(1)
select @left = '1',@right = '2'
while @left < 4
begin
select @SQL = '
update t1.PortID' + @left + ' = t2.PortID' + @right + '
t1.Distance' + @left + ' = t2.Distance' + @right + '
t1.Rating' + @left + ' = t2.Rating' + @right + '
'+CASE @left
when '1' then
' t1.PortID' + cast(cast(@left as int)+1 as varchar(1)) + ' = t2.PortID' + cast(cast(@right as int)+1 as varchar(1)) +'
t1.PortID' + cast(cast(@left as int)+2 as varchar(1)) + ' = t2.PortID' + cast(cast(@right as int)+2 as varchar(1)) +'
t1.PortID' + cast(cast(@left as int)+3 as varchar(1)) + ' = t2.PortID' + cast(cast(@right as int)+3 as varchar(1)) +'
t1.Distance' + cast(cast(@left as int)+1 as varchar(1)) + ' = t2.Distance' + cast(cast(@right as int)+1 as varchar(1)) +'
t1.Distance' + cast(cast(@left as int)+2 as varchar(1)) + ' = t2.Distance' + cast(cast(@right as int)+2 as varchar(1)) +'
t1.Distance' + cast(cast(@left as int)+3 as varchar(1)) + ' = t2.Distance' + cast(cast(@right as int)+3 as varchar(1)) +'
t1.Rating' + cast(cast(@left as int)+1 as varchar(1)) + ' = t2.Rating' + cast(cast(@right as int)+1 as varchar(1)) +'
t1.Rating' + cast(cast(@left as int)+2 as varchar(1)) + ' = t2.Rating' + cast(cast(@right as int)+2 as varchar(1)) +'
t1.Rating' + cast(cast(@left as int)+3 as varchar(1)) + ' = t2.Rating' + cast(cast(@right as int)+3 as varchar(1)) +'
' when '2' then
' t1.PortID' + cast(cast(@left as int)+1 as varchar(1)) + ' = t2.PortID' + cast(cast(@right as int)+1 as varchar(1)) +'
t1.PortID' + cast(cast(@left as int)+2 as varchar(1)) + ' = t2.PortID' + cast(cast(@right as int)+2 as varchar(1)) +'
t1.Distance' + cast(cast(@left as int)+1 as varchar(1)) + ' = t2.Distance' + cast(cast(@right as int)+1 as varchar(1)) +'
t1.Distance' + cast(cast(@left as int)+2 as varchar(1)) + ' = t2.Distance' + cast(cast(@right as int)+2 as varchar(1)) +'
t1.Rating' + cast(cast(@left as int)+1 as varchar(1)) + ' = t2.Rating' + cast(cast(@right as int)+1 as varchar(1)) +'
t1.Rating' + cast(cast(@left as int)+2 as varchar(1)) + ' = t2.Rating' + cast(cast(@right as int)+2 as varchar(1)) +'
' when '3' then
' t1.PortID' + cast(cast(@left as int)+1 as varchar(1)) + ' = t2.PortID' + cast(cast(@right as int)+1 as varchar(1)) +'
t1.Distance' + cast(cast(@left as int)+1 as varchar(1)) + ' = t2.Distance' + cast(cast(@right as int)+1 as varchar(1)) +'
t1.Rating' + cast(cast(@left as int)+1 as varchar(1)) + ' = t2.Rating' + cast(cast(@right as int)+1 as varchar(1)) +'
' when '3' then
' t1.PortID' + @left + ' = null '+
' t1.Distance' + @left + ' = null '+
' t1.Rating' + @left + ' = null '
else '' END + '
from [TravelRank] t1
inner join [TravelRank] t2
on t1.destination = t2.destination
where t1.PortID1 = 101'
print @SQL
-- exec (@SQL)
select @left = cast(cast(@left as int) + 1 as varchar(1))
, @right = cast(cast(@right as int) + 1 as varchar(1))
end
You were missing a couple of concats. This runs now, but I'm not completely sure if it's the output you were expecting.

Similar Messages

  • UPDATE QUERY can't update table

    Hi,
    During 1500-2000 concurrent users, DB Transaction locks occur. So that Update query can't update table and we get inconsistent data. How can we avoid this inconsistent data?? Why we get transaction locks??
    Eg. In update query it update the status of user with completed; but because of transaction lock  update query can't update status of user it remains uncompleted. So we can get wrong status of user(inconsistent data). Why UPDATE query update the status
    of user???
    update table set status='completed', date=@p2,score=@p3 where id=@p1

    You are not getting inconsistent data, you are getting the data according to the isolation level you are running under. The isolation level determines the locking model and therefore determines any bad dependencies you may experience. Reducing the bad dependencies
    through higher isolation level will lower concurrency. *This* is the core concept of Transactional Processing theory.
    Furthermore there is not really such a thing as a DB Transaction lock - at least not in the way you mean. SQL server does use DB locks (such as Shared transaction workspace and Exclusive transaction workspace) but the highest level of lock escalation is
    the object level (heap or btree) so those are the things you are really interested in. In the ideal would you want all Exclusive, Shared and U locks to be taken at the RID (heaps) or Key (cluster tables) level - and only have few of them per query.
    In conclusion think carefully about your query and how it is implimented under the covers by the database engine.
    Regards,
    Mark Broadbent.
    Microsoft Certified Master
    Contact me through twitter |
    blog | sqlcloud
    Please click "Propose as answer" if a post solves your problem
    or/and vote the post up if it's been helpful.

  • How can I make my query to compare only columns of two tables... not the storage information?

    11GR2
    =-----------------------------------
    I am using below querry to compare two table that has same name, under two different users... But after making storage information false like below and  if the storage information is different on column level than it create "Alter modify " statements for the column ... How can I make my query to compare only columns of two tables... not the storage information?
    begin
    DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'PRETTY', TRUE);
    DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'SQLTERMINATOR',TRUE);
    DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'SEGMENT_ATTRIBUTES', FALSE);
    DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'STORAGE', FALSE);
    DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'TABLESPACE',FALSE);
    DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'CONSTRAINTS',FALSE);
    DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'REF_CONSTRAINTS',FALSE);
    DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'CONSTRAINTS_AS_ALTER',FALSE);
    End;
    select REGEXP_REPLACE(dbms_metadata_diff.compare_alter('TABLE','TABLE_NAME_A','TABLE_NAME_A','USER1','USER2'),('USER1...'),'', 1, 0, 'i') from dual

    I am using below querry to compare two table that has same name, under two different users... But after making storage information false like below and  if the storage information is different on column level than it create "Alter modify " statements for the column ... How can I make my query to compare only columns of two tables... not the storage information?
    If you want help you have to SHOW us what you are doing and how you are doing it; you can't just try to tell us in your own words.
    We can't see your computer screen.

  • Select query, case statment

    Hi,
    I have two tables Registration and Place.
    "Registration" table has Name and Registration_id column and "place" table has Registration_id, task_id and state columns. So both tables have inner join on Registration_id column.
    now one Registration_id has two task_id
    so for example,
    Name
    Registration_id
    task_id
    State
    Vicky
    101
    11
    NY
    Vicky
    101
    12
    CA
    Now in output table "Person",  I have 2 columns, one is Birth and one is Death.
    So one person has 1 Registration_id associated and that Registration_id has two records in "Place" table,
    Now condition is like this, for same Registration_id if task_id = 11 put state value in Birth column and  if task_id = 12 put state value in Death column.
    So for example output (Select query for Person table)should looks like below,
    Name
    Registration_id
    Birth
    Death
    Vicky
    101
    NY
    CA
    So please tell me select query for this output from above 2 source tables which I use to insert records into "Person" table. (Just for information - I have 12 source tables and there are many columns I have to select from these source tables
    and this is the part of that select statement where I am stuck for now). Please let me know if you need any more detail on this.
    I think, we have to write subquery in select statement. like,
    Select
    Birth =(select
    STATE from PLACE pl inner join on Registration R ON R.Registration_id = pl.Registration_id
    where
    TASK_ID = 136)
    , Death
    =(select
    STATE from PLACE pl inner join on Registration R ON R.Registration_id = pl.Registration_id
    where
    TASK_ID = 141)
    , other columns
    From other source tables.
    Thank you in advance.
    Vicky

    >> I have two tables Registration and Place [only one?]. <<
    Please post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn how to follow ISO-11179 data element naming conventions and formatting rules. Temporal data should
    use ISO-8601 formats. Code should be in Standard SQL as much as possible and not local dialect. 
    This is minimal polite behavior on sql forums. You have been told about this before!! Why do you still behave like this? PLEASE EXPLAIN TO EVERYONE HERE WHY THE MOST BASIC SOCIAL RULES DO NOT APPLY TO YOU??
    >> Please let me know if you need any more detail on this. <<
    WE NEED EVERYTHING! You posted nothing. You do not even know that you should have had “state_code CHAR(2) NOT NULL” in some DDL. You still not know that rows are not records, that tables models sets not single items, etc. 
    Please quit posting until you come up to the level of a total noob who read the forum rules.
    We get tired of doing homework for people who are ignorant, incompetent and rude. 
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • Execute dynamic query stored as varchar in a different table.

    Hi,
    I have a table with a column as query,which stores the query i want to fire.for eg.my query will be like :-
    Select name,empid from employees where name =null
    Now,I have a stored procedure in which i have declared  a variable @query .I want to replace the following line of code .
    if exists(Select name ,empid from employees where name=null)
    begin
    --send mail
    end
    as
    if exists(@query)
    But it doesnt seem to work because it is taking the @query as varchar and not an actual t-sql command.I want to keep the query dynamic as each row in my table has a different query to fire.

    And only to clarify Praveen's solution:
    DECLARE @DynamicSQl nvarchar(250), @x nvarchar(100)
    SELECT @x = '@retVal int output'
    DECLARE @retVal int
    SET @DynamicSQl = 'SET @retVal = CASE WHEN EXISTS (' + @query + ') THEN 1 ELSE 0 END'
    EXEC sp_executesql @DynamicSQl, @x, @retVal output
    IF @retVal > 0
    BEGIN
    print 'send mail'
    END
    However, Nimo should probably have some error handling, as the stored query may not be syntactically correct. And even if it is syntactically correct, it may not play well with EXISTS. Case in point: a query that starts with a CTE.
    And of course, if any user is permitted to add these queries, and this code is exeuted with high permissions, they can inject queries that perform evil things they don't have permissions to do themselves, so be careful.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Slow running query on heavily updating table

    Hi,
    I am working on a live gps tracking project. The project is using SQL Server 2008 web edition. There are thousands of devices which are sending data packets in every 10 seconds or less depending on various settings to the server. On server there is a tcp
    server listener program which reads and parse data and insert it into a "Table-A". Table-A has a trigger which updates Table-B on each insertion (Table-B is used to show live updated status on website). Now Table-A has millions of records per day
    and high insertion rate per second.
    We also need to show the history reports and other reports using "Table-A". The problem is query on "Table-A" is very slow and affacts the insertion on "Table-A". Please help to overcome this problem.

    Since there are frequent inserts ,I believe you are selecting records using NOLOCK hint to avoid shared locks.
    Niting,
    I am pretty much sure in OP scenario NOLOCK will cause blunder. Please don't advise NOLOCK on forum where we have no or minimal information about OP database and infrastructure. Its not a good coding practice.
    Your comment to perform regular stats update also does not makes sense, are you sure stats is the issue I can sense some app design problem.
    Ganesh,
    I guess trigger on Table A is making things slow as it has to complete and I guess this is what taking time , I am not sure.
    Please mark this reply as answer if it solved your issue or vote as helpful if it helped so that other forum members can benefit from it
    My Technet Wiki Article
    MVP

  • ADF Mobile updating a column for all the rows

    Hi Every one,
    This is My ADFMobile Usecase:
    In My use case, I created DB Webservices  and created a  datContol on it .
    I have few AMX pages in my Taskflow.
    1st page: Authentication page with userid and p/w.
    2nd page:Need to get DeptID as  LOV and a submit button.
    3rd Page:Need to get all Employees in that Department. Need to get Empl_name, Empl_Id, Empl_salary and Empl_ Attendence. and a SYNC Button.
    Up to now every thing is fine.
    But I need to change  Empl_Attendence Column As absent or Present . I used  SelectOneChoice. Default there will be PRESENT value in back end.So after Selecting  SlectOneChoice the value (Absent) should Automatically update in DB for that row.
    Requirement:
    So How to write logic for the SYNC button to update the Empl_ Attendence for all the rows at a time.
    Thanks In Advance
    Regards
    Varma.

    Hi Every one,
    This is My ADFMobile Usecase:
    In My use case, I created DB Webservices  and created a  datContol on it .
    I have few AMX pages in my Taskflow.
    1st page: Authentication page with userid and p/w.
    2nd page:Need to get DeptID as  LOV and a submit button.
    3rd Page:Need to get all Employees in that Department. Need to get Empl_name, Empl_Id, Empl_salary and Empl_ Attendence. and a SYNC Button.
    Up to now every thing is fine.
    But I need to change  Empl_Attendence Column As absent or Present . I used  SelectOneChoice. Default there will be PRESENT value in back end.So after Selecting  SlectOneChoice the value (Absent) should Automatically update in DB for that row.
    Requirement:
    So How to write logic for the SYNC button to update the Empl_ Attendence for all the rows at a time.
    Thanks In Advance
    Regards
    Varma.

  • Is there a way to BULK COLLECT with FOR UPDATE and not lock ALL the rows?

    Currently, we fetch a cursor on a few million rows using BULK COLLECT.
    In a FORALL loop, we update the rows.
    What is happening now, is that we run this procedure at the same time, and there is another session running a MERGE statement on the same table, and a DEADLOCK is created between them.
    I'd like to add to the cursor the FOR UPDATE clause, but from what i've read,
    it seems that this will cause ALL the rows in the cursor to become locked.
    This is a problem, as the other session is running MERGE statements on the table every few seconds, and I don't want it to fail with ORA-0054 (resource busy).
    What I would like to know is if there is a way, that only the rows in the
    current bulk will be locked, and all the other rows will be free for updates.
    To reproduce this problem:
    1. Create test table:
    create table TEST_TAB
    ID1 VARCHAR2(20),
    ID2 VARCHAR2(30),
    LAST_MODIFIED DATE
    2. Add rows to test table:
    insert into TEST_TAB (ID1, ID2, LAST_MODIFIED)
    values ('416208000770698', '336015000385349', to_date('15-11-2009 07:14:56', 'dd-mm-yyyy hh24:mi:ss'));
    insert into TEST_TAB (ID1, ID2, LAST_MODIFIED)
    values ('208104922058401', '336015000385349', to_date('15-11-2009 07:11:15', 'dd-mm-yyyy hh24:mi:ss'));
    insert into TEST_TAB (ID1, ID2, LAST_MODIFIED)
    values ('208104000385349', '336015000385349', to_date('15-11-2009 07:15:13', 'dd-mm-yyyy hh24:mi:ss'));
    3. Create test procedure:
    CREATE OR REPLACE PROCEDURE TEST_PROC IS
    TYPE id1_typ is table of TEST_TAB.ID1%TYPE;
    TYPE id2_typ is table of TEST_TAB.ID2%TYPE;
    id1_arr id1_typ;
    id2_arr id2_typ;
    CURSOR My_Crs IS
    SELECT ID1, ID2
    FROM TEST_TAB
    WHERE ID2 = '336015000385349'
    FOR UPDATE;
    BEGIN
    OPEN My_Crs;
    LOOP
    FETCH My_Crs bulk collect
    INTO id1_arr, id2_arr LIMIT 1;
    Forall i in 1 .. id1_arr.COUNT
    UPDATE TEST_TAB
    SET LAST_MODIFIED = SYSDATE
    where ID2 = id2_arr(i)
    and ID1 = id1_arr(i);
    dbms_lock.sleep(15);
    EXIT WHEN My_Crs%NOTFOUND;
    END LOOP;
    CLOSE My_Crs;
    COMMIT;
    EXCEPTION
    WHEN OTHERS THEN
    RAISE_APPLICATION_ERROR(-20000,
    'Test Update ' || SQLCODE || ' ' || SQLERRM);
    END TEST_PROC;
    4. Create another procedure to check if table rows are locked:
    create or replace procedure check_record_locked(p_id in TEST_TAB.ID1%type) is
    cursor c is
    select 'dummy'
    from TEST_TAB
    WHERE ID2 = '336015000385349'
    and ID1 = p_id
    for update nowait;
    e_resource_busy exception;
    pragma exception_init(e_resource_busy, -54);
    begin
    open c;
    close c;
    dbms_output.put_line('Record ' || to_char(p_id) || ' is not locked.');
    rollback;
    exception
    when e_resource_busy then
    dbms_output.put_line('Record ' || to_char(p_id) || ' is locked.');
    end check_record_locked;
    5. in one session, run the procedure TEST_PROC.
    6. While it's running, in another session, run this block:
    begin
    check_record_locked('208104922058401');
    check_record_locked('416208000770698');
    check_record_locked('208104000385349');
    end;
    7. you will see that all records are identified as locked.
    Is there a way that only 1 row will be locked, and the other 2 will be unlocked?
    Thanks,
    Yoni.

    I don't have database access on weekends (look at it as a template)
    suppose you
    create table help_iot
    (bucket number,
    id1    varchar2(20),
    constraint help_iot_pk primary key (bucket,id1)
    organization index;not very sure about the create table syntax above.
    declare
      maximal_bucket number := 10000; -- will update few hundred rows at a time if you must update few million rows
      the_sysdate date := sysdate;
    begin
      truncate table help_iot;
      insert into help_iot
      select ntile(maximal_bucket) over (order by id1) bucket,id1
        from test_tab
       where id2 = '336015000385349';
      for i in 1 .. maximal_bucket
      loop
        select id1,id2,last_modified
          from test_tab
         where id2 = '336015000385349'
           and id1 in (select id1
                         from help_iot
                        where bucket = i
           for update of last_modified;
        update test_tab
           set last_modified = the_sysdate
         where id2 = '336015000385349'
           and id1 in (select id1
                         from help_iot
                        where bucket = i
        commit;
        dbms_lock.sleep(15);
      end loop;
    end;Regards
    Etbin
    introduced the_sysdate if last_modified must be the same for all updated rows
    Edited by: Etbin on 29.11.2009 16:48

  • Issue In internal table data population in the o/p

    Dear Guru , I have encountered an issue for which i am not able to findout the logic  . I have an internal table through which i am populating the below data for detail report format :->
    Plant     Material Number          Storage Loc     Movement Type          Avg Days
    019     0820B0073          MOD3          101               space
    019     0820B0073          MOD3          101               space
    019     0820B0073          MOD3          101               space
    019     0820B0073          MOD3          101               space
    019     0820B0073          MOD3          101               space
    020     0820B0074          MOD4          101               space
    020     0820B0074          MOD4          101               2
    020     0820B0074          MOD4          101               3
    The requirment is like this the summary report should show o/p like below addition of all the rows with respect to plant , material, storage location and movement type :-
    Plant     Material Number          Storage Loc     Movement Type          Avg Days
    019     0820B0073          MOD3          101               space
    020     0820B0074          MOD4          101               5
    but when i am adding it with respect to plant, material, storage location and movement type the o/p i am getting is like below
    Plant     Material Number          Storage Loc     Movement Type          Avg Days
    019     0820B0073          MOD3          101               0
    020     0820B0074          MOD4          101               5
    becasue addition of 5 spaces ( Avg Days )of plant 019 is coming as ZERO --> 0
    so Guru what logic i should use to get the proper o/p,..I have Used Following logic to perform summation with respect to plant, material , storage loc and movement type.
    CLEAR: wa_mkpf_mseg, w_werks, w_matnr, w_lgort, w_bwart.
    LOOP AT t_mkpf_mseg INTO wa_mkpf_mseg.   
    IF wa_mkpf_mseg-werks EQ w_werks AND wa_mkpf_mseg-matnr EQ w_matnr AND wa_mkpf_mseg-lgort EQ w_lgort AND wa_mkpf_mseg-bwart EQ w_bwart.
          CLEAR: wa_p_coi.
          READ TABLE t_p_coi INTO wa_p_coi WITH KEY werks = wa_mkpf_mseg-werks matnr = wa_mkpf_mseg-matnr lgort = wa_mkpf_mseg-lgort bwart = wa_mkpf_mseg-bwart.
         IF sy-subrc = 0.
         wa_p_coi-Avg Days    = wa_p_coi-Avg Days   + wa_mkpf_mseg-Avg Days.
         MODIFY t_p_coi FROM wa_p_coi TRANSPORTING Avg Days   .
         CLEAR: wa_p_coi, wa_p_coi.
         endif.
    ELSE.
          wa_p_coi-werks                     = wa_mkpf_mseg-werks.
          wa_p_coi-matnr                     = wa_mkpf_mseg-matnr.
          wa_p_coi-bwart                   = wa_mkpf_mseg-bwart.
          wa_p_coi-lgort                     = wa_mkpf_mseg-lgort.
          wa_p_coi-Avg Days                  = wa_mkpf_mseg-Avg Days   .
         APPEND wa_p_coi TO t_p_coi.
               CLEAR: wa_p_coi.
    ENDIF.
        w_werks = wa_mkpf_mseg-werks.
        w_matnr = wa_mkpf_mseg-matnr.
        w_lgort = wa_mkpf_mseg-lgort.
        w_bwart = wa_mkpf_mseg-bwart.
       CLEAR: wa_mkpf_mseg.
      ENDLOOP.

    The soln what i found after working out
    CLEAR: wa_mkpf_mseg, w_werks, w_matnr, w_lgort, w_bwart.
    LOOP AT t_mkpf_mseg INTO wa_mkpf_mseg.
    IF wa_mkpf_mseg-werks EQ w_werks AND wa_mkpf_mseg-matnr EQ w_matnr AND wa_mkpf_mseg-lgort EQ w_lgort AND wa_mkpf_mseg-bwart EQ w_bwart.
    CLEAR: wa_p_coi.
    READ TABLE t_p_coi INTO wa_p_coi WITH KEY werks = wa_mkpf_mseg-werks matnr = wa_mkpf_mseg-matnr lgort = wa_mkpf_mseg-lgort bwart = wa_mkpf_mseg-bwart.
    IF sy-subrc = 0.
    if wa_p_coi-Avg Days  = ' ' and wa_mkpf_mseg-Avg Days = ' '.
    wa_p_coi-Avg Days = ' '.
    ELSE
    wa_p_coi-Avg Days = wa_p_coi-Avg Days + wa_mkpf_mseg-Avg Days.
    Endif.
    MODIFY t_p_coi FROM wa_p_coi TRANSPORTING Avg Days .
    CLEAR: wa_p_coi, wa_p_coi.
    endif.
    ELSE.
    wa_p_coi-werks = wa_mkpf_mseg-werks.
    wa_p_coi-matnr = wa_mkpf_mseg-matnr.
    wa_p_coi-bwart = wa_mkpf_mseg-bwart.
    wa_p_coi-lgort = wa_mkpf_mseg-lgort.
    wa_p_coi-Avg Days = wa_mkpf_mseg-Avg Days .
    APPEND wa_p_coi TO t_p_coi.
    CLEAR: wa_p_coi.
    ENDIF.
    w_werks = wa_mkpf_mseg-werks.
    w_matnr = wa_mkpf_mseg-matnr.
    w_lgort = wa_mkpf_mseg-lgort.
    w_bwart = wa_mkpf_mseg-bwart.
    CLEAR: wa_mkpf_mseg.
    ENDLOOP.

  • How to update table J_1IPART1,without replacing the old values

    Helllo Friends
    Problem:
    When I capture the  excisable document in T-code J1IEX, the table J_1IPART1 does not  get updated ,but when I do the good receipts by 101,then entry in the above table get updated ,by replacing the  previous entry.
    What should I do so that table J_1IPART2 hold all the captured values without replacing the old values.
    And after what time of interval do I need to update the register, is it on daily bases or on monthly bases

    Try these steps:
    1. Post MIGO without excise entry
    2. J1I5 - Update register for RG23A Part1 with classification ROP.
    3. Post excise Invoice through J1IEX
    You should update the register on daily basis.

  • Update query issue to update middle (n records) of the rows in a table

    Hi
    I have a below requirement for that I gone thru one below appoch to fulfill my requirement.
    Requirement:
    I need to pull 3 crore data thru ODI, source table does not have a primary key and it have 200 columns with 3 crores records (it has a 25 columns as composite key).
    I need to populate those 3 crores records into target oracle DB but when I tried to load 3 crores at time I got an error so I approch incremental load, since for that I need to update for each 1 crore records with flg1,flg2 anf flg3 (flag values), for this update I have added one more column in source table using those flag values I can populate 1 crore records in target machine.
    Approch
    For aove requirement I writem below query to update flg1 for first crores records update tbl_name set rownum_id='flg1' where rownum<=10000000; and it updated successfully without any error, for second, to update flg2 for 2nd crore records I wrote below update query and it execute 20min and given *0 rows updated* Please help if below query is wrong
    Query: update tbl_name set rownum_id='flg2' where rownum<=20000000 and rownum_id is NULL;
    Thanks in advance
    Regards,
    Phanikanth

    A couple of thoughts.
    1. This forum is in English and accessed by people in more than 100 countries. Use metric counts not crore. Translate to million, billions, trillions, etc.
    2. No database version ... makes helping you very hard.
    3. 200 columns with 25 in a composite key is a nightmare by almost any definition ... fix your design before going any further.
    4. What error message? Post the complete message not just your impression of it.
    5. Oracle tables are heap tables .. there is no such concept as the top, the bottom, or the middle.
    6. If you are trying to perform sampling ... use the SAMPLE clause (http://www.morganslibrary.org/reference/select.html#sssc).
    7. What is ODI? Do not expect your international audience to know what the acronym means.

  • Update table HRP1001. Change the Position and the Org Unit.

    Hi,
    I am new to SAP HR and have been given a work in this area. The requirement is to update the relationship table HRP1001 replacing the old Manager' Position and the Org Unit with the New Manager's Position and the Org. Unit.
    I have some how found out the way to get the Postion and the Org unit of the old manager. Now I am replacing the same with the new details using the Update HRP1001 Command but this is the old and not recommended method acheiving this task.
    Can anyone please suggest me any Function Module OR the BAPI to update the HRP 1001 table with the New MAnager;s Position and the Org Unit.
    Thanks...!!!
    Regards,
    Deepak.

    Hi Kalpesh,
    I am using the FM: 'BAPI_HRMASTER_SAVE_REPL_MULT'but still not updating. I am trying to change the Position and the Org unit but not successful yet.
    I first used the Operator 'I' withi the table BAPIHROBJ-OPERATOR, it failed then I tried 'U' for update it still failed. Can you please let me know how many such operations possible with their charecter values apart from I & U. the domain value set does not exist as it is char1.
    Now I came to know that I have to terminate the old relationship by changing the ENDDA and create a new one with the new BEGDA as tomorrow's date.
    Can you please suggest something.
    Regards,
    Deepak.

  • What are the Update tables?

    In LO Delta scenario, Data posted parallel into document tables and update tables. What are the Document tables? What are the Update tables?
    Give example for Application 11, which is document tables, and update tables?

    Hello Mannev,
    Document tables are the actual application tables where the data is posted when you post a document in R/3.
    Examples can be MSEG, VBRK etc.
    Update tables are the intermediate tables which store data read from document tables. The V3 runs collects deltas in form of LUWs from these update tables and populates the delta queues.
    hope this helps..
    thanks,

  • Update table based on ID reference comparing each column and value

    Hi,
    Through UI user can update any information and click save. In backend i will be receiving only ID as reference . Based on the ID value i should update multiple tables wherever i have the reference tables. Here i will not get the values or column name updated.
    I just get a ID to find which row is updated.
    I should do a comparision now. 
    I have a history table where i get the row before updation. and i get a row after updation from current data i.e. from ssdb_Railroad[This will be updated by java after updation we will get the ID inorder to update remaining tables]. Now i need to compare
    both the table column values and know which column is updated and after getting the value i should update reference tables.
    Below is the structure for comparision table , History table and Main table.
    Create table Comparision_History (
     ID   int IDENTITY(1,1) PRIMARY KEY,
     InsertUser_UpdateUser varchar(50),
     Old_ColVal  varchar(100),
     New_ColVal  varchar(100),
     TableName   varchar(100),
     [Action]     varchar(50),
     InsertDate_UpdateDate Datetime NOT NULL DEFAULT getdate()
    CREATE TABLE SSDB_Railroad_History (
        ID         int IDENTITY PRIMARY KEY,
    SCAC       varchar(4) ,
    Name       varchar(50) NOT NULL,
    RailroadID int NOT NULL UNIQUE,
    RC2Key
      varchar(50),
    NOTES      varchar(1000),
    [Action]   varchar(50),
    InsertDate_UpdateDate  Datetime NOT NULL DEFAULT getdate(),
    InsertUser_UpdateUser  varchar(50),
    CREATE TABLE SSDB_Railroad (
        ID   int IDENTITY(1,1)PRIMARY KEY,
    SCAC varchar(4) UNIQUE,
    Name varchar(50) NOT NULL,
    RailroadID int NOT NULL UNIQUE,
    RC2Key
    varchar(50),
    InsertDate Datetime NOT NULL DEFAULT getdate(),
    UpdateDate Datetime,
    InsertUser varchar(50),
    UpdateUser varchar(50)
    Here SSDB_Railroad table and History table needs to be compared and get a updated value and it should be inserted in a comparision table. as well as it should be updated in reference tables.
    Please help me with the code.
    Thanks in Advance
    Deepa

    Hi Deepa_Deepu,
    According to your description, personally, the merge function can meet your requirements. Usually, we can synchronize two tables by updating or inserting rows in a target table based on differences found in the source tables. Just as your description, when
    the value of ID and InsertDate_UpdateDate in the source table matches a value, update them in the target table. When the values does not match, the source row is inserted into the target table.
    For more information, see: using MERGE to perform UPDATE and INSERT operations on a target table by using a derived source table.
    http://msdn.microsoft.com/zh-cn/library/bb510625.aspx
    Regards,
    Sofiya Li
    Sofiya Li
    TechNet Community Support

  • Use of update table in Unserialised V3?

    HI Pioneers,
    Can any one let me know the advantage of Update table in Unserialised V3 update mode?
    Thanks,James

    hi,
    Update table is to store the posted records(V3 update), so the the collective run can pick uprecords from there.
    Unserialized V3 update is not used now a days.
    Only queued Delta is used
    Regards,
    Ramesh

Maybe you are looking for

  • MBP Santa Rosa Airport Issues w/ Leopard

    Hi everyone, I've noticed a few "quirks" since upgrading to Leopard. Whenever my Macbook Pro (Santa Rosa, 2.4 GHz, 17", 4GB RAM) is searching for a wireless network to join, the system becomes completely unresponsive. The mouse pointer stutters and j

  • Crystal Reports 2008 Formula in Cross-Tab Error Not Supported

    I have a crosstab that was created in Crystal XI and when I opened the report in Crystal 2008 I receive an Error "Not Supported" when I removed the fromula that was in the Crosstab the report displayed. The following is the formula that is within the

  • Auto brightness of screen and keyboard backlight not working

    Basically, since I updated to OS X Lion, the auto brightness feature for the screen and keyboard hasnt been working, despite the fact I have it turned on Thanks in advance for your help

  • Software-updater

    software-updater

  • Issue in reverse engineering the model source is excel

    Hi Everyone, I am new to ODI, i am trying to export the excel file data into oracle table. For doing this created physical and logical schema for Excel file and Oracle database. Tried to created a Model and reverse engineer the excel file to get the