Creating a Dynamic Update Statement based on Select

hi,
i'm trying to create a dynamic update statement based on select statement
my requirment is to query a joint tables and get the results then based on the results i need to copy all the data and create an update statement for each row
for ex
the update statement should look like this
update iadvyy set SO_SWEEP_CNT = '1' where inst_no = '003' and memb_cust_no = 'aaaaaaaaaaaaaaaa';
and the select statement like the following
select substr(key_1,11,9) account_no,sord_mast SO_SWEEP_CNT from
select acct_no,count(*) sord_mast from
(select from_acct_no acct_no,update_mast
from sord where FROM_SYS in ('DEP','INV') and TERM_DATE > 40460
union all
select to_acct_no acct_no,update_mast
from sord where TO_SYS in ('DEP','INV') and TERM_DATE > 40460)
group by Acct_no)
right outer join
invm
on
key_1 = '003'||acct_no
where sord_mast > 0;
so taking the above two columns from the above select statement and substitue the values as separate update statement.
is that doable , please share your knowledge with me if poosible
thanks in advanced

is that doable , please share your knowledge with me if poosibleyes
The standard advice when (ab)using EXECUTE IMMEDIATE is to compose the SQL statement in a single VARCHAR2 variable
Then print the SQL before passing it to EXECUTE IMMEDIATE.
COPY the statement & PASTE into sqlplus to validate its correctness.

Similar Messages

  • Dynamic UPDATE statement with parameters for column names.

    Hello,
    On this* website I read "The SQL string can contain placeholders for bind arguments, but bind values cannot be used to pass in the names of schema objects (table or column names). You may pass in numeric, date, and string expressions, but not a BOOLEAN or NULL literal value"
    On the other hand, in this Re: execute immediate with dynamic column name update and many other
    posts people use EXECUTE IMMEDIATE to create a dynamic UPDATE statement.
    dynSQL:='UPDATE CO_STAT2 CO SET CO.'||P_ENT_B_G_NAME||' = '||P_ENT_E_G_WE||'
    WHERE ST IN
    (SELECT ST FROM STG_CO_STAT2_TEST CO WHERE
    '||P_ST||' = CO.ST AND
    CO.'||P_ENT_E_G_NAME||' > '||P_ENT_E_G_WE||' AND
    CO.'||P_ENT_B_G_NAME||' < '||P_ENT_E_G_WE||');';
    EXECUTE IMMEDIATE dynSQL ;
    Since this statement is part of a Stored Procedure, I wont see the exact error but just get a ORA-06512.
    The compiling works fine and I use Oracle 11g.
    http://psoug.org/definition/EXECUTE_IMMEDIATE.htm

    OK I extracted from all of your posts so far that I have to use "bind-variables with :"
    From all the other tuorials and forums posts, I assume using the pipe is correct so I added those as well into the script:
    set serveroutput on format wraped;
    DECLARE
    dynSQL VARCHAR2(5000);
    P_ENT_E_G_NAME VARCHAR2 (100) :='test1'; P_ENT_E_G_WE VARCHAR2 (100) :='01.02.2012'; P_ENT_B_G_NAME VARCHAR2 (100) :='01.01.2012';
    P_ST                VARCHAR2 (100) :='32132';
    BEGIN
    dynSQL:= 'UPDATE CO_STAT2 CO SET CO.'||:P_ENT_B_G_NAME||' = '||:P_ENT_E_G_WE||'
                  WHERE ST IN (SELECT ST FROM STG_CO_STAT2_TEST CO WHERE
                  '||:P_ST||'                           = CO.ST                  AND
                  CO.'||:P_ENT_E_G_NAME||'     > '||:P_ENT_E_G_WE||' AND
                  CO.'||:P_ENT_B_G_NAME||'    
    < '||:P_ENT_E_G_WE||')';
    --this is somehow missing after the last < '||:P_ENT_E_G_WE||')';
    dbms_output.enable;
    dbms_output.put(dynSQL);
    --EXECUTE IMMEDIATE dynSQL;    
    END;Problem:I think I figured it out, the dates that I parse into the query need additional '

  • Dynamic Update statements

    Hello,
    I have one SP to do DMLs. This SP works fine without any problem, but for Update I have problem to construct. The update statement should be constructed depending on the values.
    For example, in a table we may have so many columns, but only few non primary key columns are updated. The SP is given below.
    Following is the update statement. the set_nk_update_cols should be dynamic.
       '    if rec.operation$ = ''UN'' then ' ||
                     '      update <owner>.' || p_target ||
                     '         set ' || replace(set_nk_update_cols,'= ','= rec.') ||
                     '       where (' || pk_target || ') = (select rec.' || replace(pk_target,',',',rec.') ||
                     '                                        from dual ' ||

    I just did something like this not long ago
    The trick is to build your 2 columns lists using LISTAGG seperately.
    1) build your PK col list. Look into dba_ind_columns for this.
    2) build your full col list. Look into dba_tab_columns
    3) splice them all together in the right place:  ie  PK list is:  where col1 and col2 and col3 .... etc.  Full list is: select col1, col2, col3 ... etc.
    [edit]
    Something else you may want to do to make things more "readable"
    WITH w_template AS
       ( SELECT TO_CLOB(
             RTRIM(q'[UPDATE <table_name>           ]')||CHR(10)||
             RTRIM(q'[   SET                        ]')||CHR(10)||
             RTRIM(q'[<set_cols>                    ]')||CHR(10)||
             RTRIM(q'[ WHERE                        ]')||CHR(10)||
             RTRIM(q'[<where_cols>                  ]')||CHR(10)||
             RTRIM(q'[;                             ]')||CHR(10)
             ) tform
         FROM dual
       w_main AS (
          SELECT DISTINCT
                   dtc.table_name,
                   LISTAGG ( ?? )  set_cols,
                   LISTAGG ( ?? )  where_cols
             FROM dba_tab_columns dtc,
                  dba_ind_columns dic
            WHERE ???
    Select replace ( replace ( replace(
                                  w_template, '<table_name>', table_name ),
                         '<set_cols>', set_cols ),
                '<where_cols>', where_cols )
      from w_template t,
           w_main;
    Something like that, anyway ..
    Sorry, I haven't got much free time to play with this at the moment, but hopefully this gives you (or somebody else?) a direction you could take.
    [/edit]

  • Dynamic Update Statement

    How do I invoke a dyanmic update statement where the variable in the WHERE clause is a varchar? for instance code below will not work b/c the value in the where clause is missing single quotation marks '<varible>'
    v_dml_str := 'UPDATE D_UNIT_KP'
    || ' SET ' || p_unit_lvl_cd1 || '=' || p_hier1
    || ' WHERE uic = ' || p_uic;
    --execute immediate v_dml_str;
    DBMS_OUTPUT.PUT_LINE(v_dml_str);
    UPDATE D_UNIT_KP SET BN=WS5DAA WHERE uic = WS5DCD

    However, that should work. See example below :
    SQL> set serveroutput on
    SQL> declare
      2       p_username varchar2(30):='SYSTEM';
      3       p_status   varchar2(30):='OPEN';
      4       v_created  date;
      5       v_stmt     varchar2(1000);
      6  begin
      7       v_stmt:='select created from dba_users where username=:b1 and account_status=:b2';
      8       execute immediate v_stmt into v_created using p_username,p_status;
      9       dbms_output.put_line(v_created);
    10  end;
    11  /
    10-APR-03
    PL/SQL procedure successfully completed.You maybe miss some variables in the USING clause, as it shows here below (I removed the p_status from the USING clause) :
    SQL> declare
      2       p_username varchar2(30):='SYSTEM';
      3       p_status   varchar2(30):='OPEN';
      4       v_created  date;
      5       v_stmt     varchar2(1000);
      6  begin
      7       v_stmt:='select created from dba_users where username=:b1 and account_status=:b2';
      8       execute immediate v_stmt into v_created using p_username;
      9       dbms_output.put_line(v_created);
    10  end;
    11  /
    declare
    ERROR at line 1:
    ORA-01008: not all variables bound
    ORA-06512: at line 8Count the number of bind variables used, you should have the same number of variables. Even if you are using the same bind variable more than once, the variables should be repeated, as the following example :
    SQL> declare
      2       p_username varchar2(30):='SYSTEM';
      3       p_status   varchar2(30):='OPEN';
      4       v_created  date;
      5       v_stmt     varchar2(1000);
      6  begin
      7       v_stmt:='select created from dba_users where username=:b1 and username=:b1';
      8       execute immediate v_stmt into v_created using p_username;
      9       dbms_output.put_line(v_created);
    10  end;
    11  /
    declare
    ERROR at line 1:
    ORA-01008: not all variables bound
    ORA-06512: at line 8
    SQL> declare
      2       p_username varchar2(30):='SYSTEM';
      3       p_status   varchar2(30):='OPEN';
      4       v_created  date;
      5       v_stmt     varchar2(1000);
      6  begin
      7       v_stmt:='select created from dba_users where username=:b1 and username=:b1';
      8       execute immediate v_stmt into v_created using p_username,p_username;
      9       dbms_output.put_line(v_created);
    10  end;
    11  /
    10-APR-03
    PL/SQL procedure successfully completed.
    SQL>Nicolas.

  • UPDATE statement based on query and return multiple value

    Hi everybody,
    I have two tables: temp3 and temp
    One of them (temp3) should be updated based on the query where clause (id and flag columns).
    I run this query but it updates all of the records in the temp3. I want to update only records with 'UPDATED' flag.
    update temp3 t3
    set (id,name,address) = (select t.id, t.name, t.address from temp t, temp3 t3
    where t.id = t3.id and t.flag = 'UPDATED');
    Does any body know how I can do it?
    I appreciate your help
    Thx

    Hello
    Basically you're missing a where clause on your update statement to restrict rows in t3 to the ones that have a corresponding row in t1.
    SQL> select * from dt_test_t1;
            ID NAME                 ADDRESS              ROW_STATUS
             1 Joseph Bloggs        Some street          UPDATED
             1 Joe Bloggs           Old street           OLD
             2 Fredrick Bloggs      New street           UPDATED
             2 Fred Bloggs          Some street          OLD
             3 Robert Bloggs        Better street        UPDATED
             3 Bob Bloggs           Some street          OLD
           100 Barry Bethel         Some street          UPDATED
           200 Giles Brandreth      Some street          UPDATED
    8 rows selected.
    SQL> select * from dt_test_t3;
            ID NAME                 ADDRESS              ROW_STATUS
             1 Joe Bloggs           Old street
             2 Fred Bloggs          Some street
             3 Bob Bloggs           Some street
             4 Joe Smith            Some street
             5 John Doe             Some street
    --this update as it stands does not work as it updates rows to have
    --null name and address where there is not a proper matching row in
    --t1
    SQL> UPDATE
      2     dt_test_t3 t3
      3  SET
      4     (       t3.name,
      5             t3.address,
      6             t3.row_status
      7     ) = (SELECT
      8             t1.name,
      9             t1.address,
    10             t1.row_status
    11          FROM
    12             dt_test_t1 t1
    13          WHERE
    14             t1.id = t3.id
    15          AND
    16             t1.row_status = 'UPDATED'
    17         );
    5 rows updated.
    SQL> select * from dt_test_t3;
            ID NAME                 ADDRESS              ROW_STATUS
             1 Joseph Bloggs        Some street          UPDATED
             2 Fredrick Bloggs      New street           UPDATED
             3 Robert Bloggs        Better street        UPDATED
    4
    5
    SQL> rollback;
    Rollback complete.
    --Now add in the where clause to make sure we're only updating rows in
    --t3 that have a corresponding row in t1:
    SQL> UPDATE
      2     dt_test_t3 t3
      3  SET
      4     (       t3.name,
      5             t3.address,
      6             t3.row_status
      7     ) = (SELECT
      8             t1.name,
      9             t1.address,
    10             t1.row_status
    11          FROM
    12             dt_test_t1 t1
    13          WHERE
    14             t1.id = t3.id
    15          AND
    16             t1.row_status = 'UPDATED'
    17         )
    18  WHERE
    19     EXISTS( SELECT
    20                     NULL
    21             FROM
    22                     dt_test_t1 t1
    23             WHERE
    24                     t1.id = t3.id
    25             AND
    26                     t1.row_status = 'UPDATED'
    27             );
    3 rows updated.
    SQL> select * from dt_test_t3;
            ID NAME                 ADDRESS              ROW_STATUS
             1 Joseph Bloggs        Some street          UPDATED
             2 Fredrick Bloggs      New street           UPDATED
             3 Robert Bloggs        Better street        UPDATED
             4 Joe Smith            Some street
             5 John Doe             Some streetHTH
    David

  • Update statement with nested selects and alias usage

    Hello, we are trying to build an update statement like this...
    update table1 t1
    set attr1 = ( select someattr
    from (nested select 1) as aux1
    (nested select 2 (nested select 2.1 + nested select 2.2)) ) as aux2
    where some_join_clauses
    where t1.attr2 = 123
    and t1.attr3 = 'abc'
    Alias t1 shound be known at the level of nested select 1,2 and 2.1, 2.2? We are receiving an error message saying that t1.someattr is an invalid identifier. Can you help? Thanks!

    mauramos wrote:
    Hello, we are trying to build an update statement like this...
    update table1 t1
    set attr1 = ( select someattr
    from (nested select 1) as aux1
    (nested select 2 (nested select 2.1 + nested select 2.2)) ) as aux2
    where some_join_clauses
    where t1.attr2 = 123
    and t1.attr3 = 'abc'
    Alias t1 shound be known at the level of nested select 1,2 and 2.1, 2.2? We are receiving an error message saying that t1.someattr is an invalid identifier. Can you help? Thanks!You can only reference elements nested 1 level deeper in a correlated update statement.
    I'd suggest you try with the MERGE statement, or alternatively, post some sample data (insert statements) and table DDL (create statements), with an 'expected output' description and we can try to help you build a suitable statement.

  • Update report based on selected LOV value

    I've searched the forum but could not find the answer how to implement the following:
    I have a form with a popup LOV, element P203_LOCATION_ID, which is populated from a query. When the user picks a value from it, a report in the same page should be refreshed. The report has query "select * from distances where d < 1 AND l = :P203_LOCATION_ID " .
    I created a dynamic action which would refresh the report on change of P203_LOCATION_ID , but the report does not change.
    After looking here, I made a hidden variable P203_SEL_LOCATION which is populated by dynamic action on change, with javascript $v('P203_LOCATION_ID') , and then a second rule in the dynamic action should refresh the report. The query in the report is changed to use :P203_SEL_LOCATION as a parameter.
    Although, when made display-only, P203_SEL_LOCATION does change (and console.log shows the selected ID), the report does not see that change and remains empty. I tried both IR and classic report, same result.
    Any help would be appreciated, how to make change in Items visible to the report?

    Hi Mila,
    I assume that you have checked that the report refresh process is happening and that by "empty" you meant that the report was not fetching any records whereas it should have for the value you see in the page.
    It could be because the changed values is not is not yet set in the session for the report to see(report fetches the bind value of the item P203_SEL_LOCATION from the session).
    You will need to add the item's value to the session before firing the report refresh.
    One way to do that would be to add a PLSQL process as true action with the sequence order lesser than the refresh.
    In the items to submit_ , give P203_SEL_LOCATION
    And the process needn't do anything(what we wanted was the P203_SEL_LOCATION be set, which would be done before executing this PLSQL)
    BEGIN
    NULL;
    END;Hope that solves your problem

  • Creating a dynamic prepared statement

    the problem:
    i have a range of paratmeters coming in from a form and need to be able to create a dynamic query string to go into a prepared statement object.
    the problem i have is there are 2 fields year range and year.
    if year range is none i need to create the query string as such :
    where the value of year can be serached on exactly
    str.append("VOLUME_YEAR = ? ");the probelm is if the year range is 5 or year range is 10 i dont know how to maipulate the query string to be able to set the string such that i can then place the year value in the place holder in preparedStatement.setInt(1, year)
    how can i create the intial query string ie.- what are the possible things that i can do. - i'm thinking of things like putting some type of between or such type query statement - but not at all sure how the syntax would go - ie. how would i use the year value and how would i create this dynamic part of the query string so that the JDBC regonises it?
    thanks for any help.
    public String setVolumeYearQuerySt(String year, String yearRange, StringBuffer str){
              String volumeYearQueryString = null;
              Sring doAction= null;
              if (yearRange.equals("None")){str.append("VOLUME_YEAR = ? ");}
              else if(yearRange.equals("5 Years")){doAction = "Nothing";}
              else if (yearRange.equals("10 Years")){doAction = "Nothing";}
              return volumeYearQueryString;
              }

    Please do not cross-post:
    http://forum.java.sun.com/thread.jspa?threadID=686789&tstart=0
    - Saish

  • Dynamic Update Statement in Native SQL

    Hi Experts,
    I want to dynamically pass the field in Update statement in Native SQL. For eg.
    data: str1 type string.
    str1 = 'MARKETS'.
    EXEC SQL.
          UPDATE PRDT.TBVEHDS4 SET (str1) = :'U'
          WHERE  VEH_NO       =  :'K1WK-54520'
          AND    SEGMENT_NO   =  :'01'
    ENDEXEC.
    But this is not taking (str1) as MARKETS field to update as U , its taking STR1 itself, Giving native SQL exception as Invalid Token as we are using DB2 as external DB system.
    I checked with field-symbols also, but nothing helped.
    Please help, thanks in Advance.
    Regards,
    Abhishek

    Hi,
    Check this demo program in SE38  ADBC_DEMO, take as example to construct your own dynamic native sql
    Regards,
    Felipe

  • Unable to create working dynamic distribution list based on manager

    Hi,
    I am struggling to create a working dynamic distribution group. I am following the instructions at http://help.outlook.com/en-gb/140/Dd264647.aspx.
    My intent is to create DDG's based on a user's manager and their job title. In my org, sales managers will typically have 3 teams reporting to them. In our AD, this would be marked by a 3-4 letter acronym in the job title field (CSO,DCO,SDCO).
    I am trying to create distribution groups for use by their manager by having the manager and job title item as the filter, using the following script:
    New-DynamicDistributionGroup -Name "GROUPNAME" -RecipientFilter {(RecipientType -eq 'UserMailbox') -and (manager -eq 'Managername') -and (title -eq 'ACRONYM')}
    As an aside, I am unable to find if the manager object should be an alias, upn or ad object. I've tried with all with no success.
    No matter what permutations of the above script I try, nothing seems to work. The group creates, but does not work at all.
    Any help you can provide would be very much appreciated!

    Hi Ed,
    I did try that, and as it turned out, I was using the wrong powershell from the start.
    The commands above are for Office 365, not on-prem Exchange 2013. Having spoken to Microsoft, it seems like the AD object for manager may not be a filterable option at all, I'm waiting to hear back.
    If this can help jog anyone's mind, the commands we're looking towards now look something like this:
    New-DynamicDistributionGroup -Name "testname" -Alias "testname" -IncludedRecipients "MailboxUsers,MailContacts" -OrganizationalUnit "domain.local/users" -ConditionalDepartment "Test" -RecipientContainer "domain.local"
    We're still looking for a filter for manager in there, and I'll update the thread if I get anything worthy of note. Bear in mind that it's going to be difficult to settle for anything less than the manager object to filter by, as our requirements pretty
    much demand it.
    Thanks all.

  • Creating a dynamic sql statement

    hi,
    I am having a query
    select w.id, w.cr_dt, w.cc_cor_addr_id, w.cc_cee_addr_id,
    w.ttl_pkgs, w.chrg_wt, wf.wb_bkg_chgd_amt + wf.wb_bkg_chgd_amt_st
    from ops_waybl_fin wf, ops_waybl w
    where wf.id = w.id
    and cre_bill_batch_dtls_id in (select get_bill_batch(1) from dual);
    the bold part is a function returns a select query.
    if the sql statement is run then we get data based on which the parent query returns data.
    how we should use a function that returns select query.
    Please advice..

    *** not tested *** Sven probably had in mind something like
    with
    v_count_cust_no as
    (select count(orr.param_val) the_count
       from ops_report_req orr
      where orr.id = :p_req_id
        and orr.param_nm = 'CUST_ID'
    v_count_cust_cntr as
    (select count(orr.param_val) the_count
       from ops_report_req orr
      where orr.id = :p_req_id
        and orr.param_nm = 'CUST_CNTR_ID'
    variant as
    (select case when (select the_count from v_count_cust_no) > 0
                 then case when (select the_count from v_count_cust_cntr) > 0
                           then 1
                           else 2
                      end
                 else case when (select the_count from v_count_cust_cntr) > 0
                           then 3
                           else 4
                      end
            end the_type
       from dual
    select w.id,w.cr_dt,w.cc_cor_addr_id,w.cc_cee_addr_id,w.ttl_pkgs,w.chrg_wt,wf.wb_bkg_chgd_amt + wf.wb_bkg_chgd_amt_st
      from ops_waybl_fin wf,ops_waybl w
    where wf.id = w.id
       and cre_bill_batch_dtls_id in (select to_number(b.id)
                                        from ops_bill_batch_dtls b,ops_cust_cntr cc
                                       where b.cust_cntr_id = cc.id
                                         and b.bill_batch_id = f1(1)
                                         and b.status_lid = 255
                                         and (((select the_type from variant) = 1
                                               and cc.cust_no in (select param_val
                                                                    from ops_report_req
                                                                   where id = :p_req_id
                                                                     and param_nm = 'CUST_ID'
                                               and cc.ID in (select param_val
                                                               from ops_report_req
                                                              where id = :p_req_id
                                                                and param_nm = 'CUST_CNTR_ID'
                                           or ((select the_type from variant) = 2
                                               and cc.cust_no in (select param_val
                                                                    from ops_report_req
                                                                   where id = :p_req_id
                                                                     and param_nm = 'CUST_ID'
                                           or ((select the_type from variant) = 3
                                               and cc.ID in (select param_val
                                                               from ops_report_req
                                                              where id = :p_req_id
                                                                and param_nm = 'CUST_CNTR_ID'
                                           or ((select the_type from variant) = 4
                                     ) Regards
    Etbin

  • Creating a calendar of events based upon selections made in other tables

    I have a Sheet that I've started working on the includes a variety of pop-up menus that reference look up tables on another sheet that contain names and prices of products. In conjunction with the drop down menus are a series of check boxes for the months in which one would want to receive the products. in each group of drop downs the order of what is selected can vary and be for example, a,b,c, or a,c,b, etc...
    I want to create a calendar looking portion of the sheet that would then express in what month each product was being received.
    I have used a LOOKUP function successfully for most of this but it seems to be erroring out in odd places. I've created a third table that looks at the first one I described, does a LOOKUP by product name and then if the product name is found it looks in the columns containing checkboxes for each month and returns either a true or false. Then on the calendar sheet - An IF statement is used to find if TRUE and then it uses text formatted as webdings to fill the box.
    I hope that explains things well enough. Any help in deciphering either why the LOOKup feature is working most places but not all or in providing a more elegant solution would be appreciated.
    Thank you,
    mmranta3777

    Your situation seems a little too complicated to provide concrete, meaningful suggestions without actually seeing what you are doing. A screen shot might be helpful, but your spreadsheet seems complicated enough that even that might not be sufficient. I can give a couple of general comments that maybe you can put to good use.
    (1) I cannot remember a time when I used LOOKUP(); almost always VLOOKUP() is what is needed (and rarely HLOOKUP() given the standard way data is typically stored in tables).
    (2) As formulas are filled down and across (especially complicated ones) it is easy to mess up the absolute cell referencing for the ranges that the lookup functions require.

  • Dynamic column output based on selection.

    Hi all,
    I have certain qualification select-options upon the selection-screen.
    I have 5001 to 5012 range of qualificaitons.
    If user select only 5001 to 5003....
    I want only 3 columns ...or else if user wants to select 5008 to 5012  output should be have columns 5008 , 09,10,11...
    I am displaying output in
    mail format only
    concanate 'COL1' COL2' 'COL2' TO STRING SEPERATED BY C=>LB.
    loop at itab.
    CONCATE ITAB-1 itab-2 itab-3 to Xstring.
    endloop.
    Thanks and regards
    sas
    Edited by: saslove sap on Jul 7, 2010 5:36 AM

    Well I have harcoded the value  as below.I have no choice find .  Instead of using mutiple 'IF' conditions ANY other options are left:
      CONCATENATE
      'Personnel Number'    'Employee GUID'   'Last Name'   'First Name'   'Position Number'   'Position Title'   'Department Number'
      'Department Name'    'Employee Subgroup text'    'Employee Group text'   'SBU Head Personnel Number'   'SBU Head GUID'
      'SBU Head Name'   'Supervisor Personnel Number'   'Supervisor GUID'   'Supervisor Name'
      'Personnel Subarea text'
    'CF1-Director function'
    'CF2-Nonexecutive director function'
    'CF3-Chief Executive function'
    'CF8-Apportionment & oversight function'
    'CF10-Compliance oversight function'
    'CF11-Money laundering reporting function'
    'CF28-Systems & controls function'
    'CF29-Significant management function'
    'CF30-Customer function, Investment Advice'
    'CF30-Customer function, Investment Mgmt'
    'CF30-Customer function, Trading'
    'Admin - FSA T&C qualifying role'
        INTO S_OUTPUT-X SEPARATED BY C_TAB.
    IF C = 'X'.
    IF '50000001' IN s_quali[].
       CONCATENATE S_OUTPUT-X    'CF1-Director function'  INTO S_OUTPUT-X SEPARATED BY C_TAB.
    endIF.
    IF '50000002' IN s_quali[].
       CONCATENATE S_OUTPUT-X    'CF2-Nonexecutive director function' INTO S_OUTPUT-X SEPARATED BY C_TAB.
    endIF.
    IF '50000003' IN s_quali[].
       CONCATENATE S_OUTPUT-X    'CF3-Chief Executive function' INTO S_OUTPUT-X SEPARATED BY C_TAB.
    endIF.
    IF '50000004' IN s_quali[].
       CONCATENATE S_OUTPUT-X    'CF8-Apportionment & oversight function' INTO S_OUTPUT-X SEPARATED BY C_TAB.
    endIF.
    IF '50000005' IN s_quali[].
       CONCATENATE S_OUTPUT-X    'CF10-Compliance oversight function' INTO S_OUTPUT-X SEPARATED BY C_TAB.
    endIF.
    IF '50000006' IN s_quali[].
       CONCATENATE S_OUTPUT-X    'CF11-Money laundering reporting function' INTO S_OUTPUT-X SEPARATED BY C_TAB.
    endIF.
    IF '50000007' IN s_quali[].
       CONCATENATE S_OUTPUT-X    'CF28-Systems & controls function' INTO S_OUTPUT-X SEPARATED BY C_TAB.
    endIF.
    IF '50000008' IN s_quali[].
       CONCATENATE S_OUTPUT-X    'CF29-Significant management function' INTO S_OUTPUT-X SEPARATED BY C_TAB.
    endIF.
    IF '50000009' IN s_quali[].
       CONCATENATE S_OUTPUT-X    'CF30-Customer function, Investment Advice' INTO S_OUTPUT-X SEPARATED BY C_TAB.
    endIF.
    IF '50000010' IN s_quali[].
       CONCATENATE S_OUTPUT-X    'CF30-Customer function, Investment Mgmt' INTO S_OUTPUT-X SEPARATED BY C_TAB.
    endIF.
    IF '50000011' IN s_quali[].
       CONCATENATE S_OUTPUT-X    'CF30-Customer function, Trading' INTO S_OUTPUT-X SEPARATED BY C_TAB.
    endIF.
    IF '50000012' IN s_quali[].
       CONCATENATE S_OUTPUT-X    'Admin - FSA T&C qualifying role' INTO S_OUTPUT-X SEPARATED BY C_TAB.
    endIF.
    endif.
      APPEND S_OUTPUT.
      LOOP AT GIT_ITAB ASSIGNING <GFS_ITAB>.
        CLEAR S_OUTPUT.
        CONCATENATE
    <GFS_ITAB>-PERNR <GFS_ITAB>-EMPGUID <GFS_ITAB>-LNAME  <GFS_ITAB>-FNAME  <GFS_ITAB>-POSITION  <GFS_ITAB>-POSTITLE <GFS_ITAB>-DEPTNO <GFS_ITAB>-DEPTNAME  <GFS_ITAB>-EMPSUBTEXT <GFS_ITAB>-EMPGRPTEXT
    <GFS_ITAB>-SBUNO <GFS_ITAB>-SBUGUID <GFS_ITAB>-SBUNAME <GFS_ITAB>-SUPVNO <GFS_ITAB>-SUPVGUID <GFS_ITAB>-SUPVNAME <GFS_ITAB>-PSUBAREATEXT
       INTO S_OUTPUT-X SEPARATED BY C_TAB.
    IF C = 'X'.
    IF '50000001' IN s_quali[].
       CONCATENATE S_OUTPUT-X    <GFS_ITAB>-CF1  INTO S_OUTPUT-X SEPARATED BY C_TAB.
    endIF.
    IF '50000002' IN s_quali[].
       CONCATENATE S_OUTPUT-X    <GFS_ITAB>-CF2 INTO S_OUTPUT-X SEPARATED BY C_TAB.
    endIF.
    IF '50000003' IN s_quali[].
       CONCATENATE S_OUTPUT-X    <GFS_ITAB>-CF3 INTO S_OUTPUT-X SEPARATED BY C_TAB.
    endIF.
    IF '50000004' IN s_quali[].
       CONCATENATE S_OUTPUT-X    <GFS_ITAB>-CF4 INTO S_OUTPUT-X SEPARATED BY C_TAB.
    endIF.
    IF '50000005' IN s_quali[].
       CONCATENATE S_OUTPUT-X    <GFS_ITAB>-CF5 INTO S_OUTPUT-X SEPARATED BY C_TAB.
    endIF.
    IF '50000006' IN s_quali[].
       CONCATENATE S_OUTPUT-X    <GFS_ITAB>-CF6 INTO S_OUTPUT-X SEPARATED BY C_TAB.
    endIF.
    IF '50000007' IN s_quali[].
       CONCATENATE S_OUTPUT-X    <GFS_ITAB>-CF7 INTO S_OUTPUT-X SEPARATED BY C_TAB.
    endIF.
    IF '50000008' IN s_quali[].
       CONCATENATE S_OUTPUT-X    <GFS_ITAB>-CF8 INTO S_OUTPUT-X SEPARATED BY C_TAB.
    endIF.
    IF '50000009' IN s_quali[].
       CONCATENATE S_OUTPUT-X    <GFS_ITAB>-CF9 INTO S_OUTPUT-X SEPARATED BY C_TAB.
    endIF.
    IF '50000010' IN s_quali[].
       CONCATENATE S_OUTPUT-X    <GFS_ITAB>-CF10 INTO S_OUTPUT-X SEPARATED BY C_TAB.
    endIF.
    IF '50000011' IN s_quali[].
       CONCATENATE S_OUTPUT-X    <GFS_ITAB>-CF11 INTO S_OUTPUT-X SEPARATED BY C_TAB.
    endIF.
    IF '50000012' IN s_quali[].
       CONCATENATE S_OUTPUT-X    <GFS_ITAB>-CF12 INTO S_OUTPUT-X SEPARATED BY C_TAB.
    endIF.
    endif.
      <GFS_ITAB>-CF2  <GFS_ITAB>-CF3 <GFS_ITAB>-CF4   <GFS_ITAB>-CF5 <GFS_ITAB>-CF6
    <GFS_ITAB>-CF7  <GFS_ITAB>-CF8 <GFS_ITAB>-CF9 <GFS_ITAB>-CF10  <GFS_ITAB>-CF11  <GFS_ITAB>-CF12
    *concatenate s_output-x c_cr into s_output-x.
        APPEND S_OUTPUT.
      ENDLOOP.

  • Generate update statement from select results

    I'm trying to generate an update statement based off select statement results.  A very basic example,
    SELECT ListID FROM DListing WHERE Status = 2
    Results return 3 rows.
    1234
    2345
    3456
    How can I take those results and turn them into WHERE criteria for UPDATE statement?
    Generated UPDATE statement should look like this.
    UPDATE DListing SET Status = 1 WHERE ListID IN (1234,2345,3456)
    I have started by creating a temp table to hold my SELECT results, but I don't know how to get those results into format for IN condition.  Right now I get 3 UPDATE statements with 1 ListID in each IN condition.
    CREATE TABLE #TempStatusUpdate(ListID INT)
    INSERT INTO #TempStatusUpdate
    SELECT ListID FROM DListing WHERE Status = 2
    SELECT 'UPDATE DListing SET Status = 1 WHERE ListID IN (' + CONVERT(VARCHAR(30),ListID) + ') AND Status = 2'
    DROP TABLE #TempStatusUpdate

    So what wrong with
    UPDTATE DListing
    SET     Status = 1
    WHERE   ListID IN (SELECT ListID FROM #TempStatusUpdate)
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Executing a Variable in a Stored Procedure containing an Update Statement

    Hi,
    I have created a Stored Procedure, it has one input parameter. Inside the Stored Procedure there are 5 other variables are declared, based on the input parameter 4 of these variables are populated.
    Fifth variable is a a concatenation of text and some of these variables and creates a dynamic Update Statement. Once it is created I want to execute this variable but it is not executing.
    Could someone please help me in knowing how to execute a variable within a stored procedure that contains an update statement.
    Thanks for your help.
    Thanks
    Vineesh
    vineesh1701

    If you have set up the variable so that it contains a valid sql update, it should work.  For example, see below, which does do an update
    use tempdb
    go
    Create Table #Test(i int);
    Insert #Test(i) Values(1);
    go
    Create Procedure TestProc As
    Begin
    Declare @SQL nvarchar(250);
    Set @SQL = 'Update #Test Set i = 2';
    --Print @SQL;
    Exec sp_executesql @SQL;
    End
    go
    Exec TestProc
    -- Test Result
    Select * From #Test;
    go
    Drop Procedure TestProc;
    go
    Drop Table #Test;
    One thing I would recommend while testing is that you print out or select the variable that contains the dynamic sql.  (Like the above code where I have a print statement.  That lets you see exactly what you are executing and if there is any problem
    with the update command. 
    As Naomi said, to get anything more than general help, you will probably have to show us your code and the parameter values you are passing when you execute the stored proc.
    Tom

Maybe you are looking for

  • Ipod Touch will not sync with Itunes 12.1.1.4 64 bit

    I have recently updated itunes and on the back of doing so my Ipod touch will not sync my library. The Ipod itself is a couple of years old but using iOS 6.1.6. I have deleted and re-installed Itunes. I have wiped my Ipod to start again. I have set i

  • Can't Install Windows 7 32-bit Drivers

    So I recently had have a hard drive replaced in a Macbook since the original failed and had to re-install Windows 7 again. After intalling Windows 7, I inserted my Snow Leapord DVD (10.6.0) and let it run the set up but it didn't install very many dr

  • Problem in JA text Download into file

    When text file is downloaded from ECC ,  the Japanese character takes more spaces in the file , comparing to Earlier version 4.6 C ( NUS) .         For that other characters left to it  displaces from its defined position thanks bobby

  • Why can't apple allow wireless synch thru the network?

    Why can't the synch of the ipad be done wirelessly through the network? It should be doable with password protection and would save the hassle of hooking up by wire which seems so retro.

  • Required some information about ACTID

    Hello Experts, Can someone please explain me the significance of ACTID in the url and what does it exactly represent? There is no documentation available in devlibrary about this ACTID. We can see actid when we try to open any webi report. Regards, J