How to skip a row to be inserted in staging table

Hi Everyone,
Actually i am transforming data from a source table to staging table and then staging to final table. I have generated a primary key using sequence. As i put the insert method of staging table as truncate/insert. So every time when mapping is loaded, staging table will be truncated and new data is inserted but as i am using sequence in staging table, it will give new numbering to old data from source table and it will duplicated this data into final target table. So for this reason i am using key look up on some of input attributes and than using expression i am trying to avoid duplication. In each output attributes in expression, I am putting the case statement
boldCASE WHEN INGRP1.ROW_ID IS NULL
THEN
INGRP1.ID
END*bold*
Due to this condition i am getting error
bold
Warning
ORA-01400: cannot insert NULL into ("SCOTT"."STG_TARGET_TABLE"."ROW_ID")
bold
But i am stuck when the value of row_id is null, at this what condition or statement should i write to skip the insertion of the data. I want to insert data only when ROW_ID IS NULL.
Kindly help me out.
Thanks
Regards
Suhail Dayer

You don't need the tables to be identical to use MINUS, only the "Select List" must match. Assuming you have the same Business key (one or more columns that uniquely identifies a row from your source data) in both the source and final table you can do the following:
- Use a Set Operation where the result is the Business Key of the Staging table MINUS the Business Key of the final table
- The output of the Set Operation is then joined to the Staging table to get the rest of the attributes for these rows
- The output of the Join is inserted into the final table
This will make sure only rows with new Business Keys are loaded.
Hope this helps,
Roald

Similar Messages

  • How to check if row to be inserted will cause circular circular loop?

    Hi-
    I'm using connect by clause to do some processing and to check that the data is not causing circular loops (with SQLCODE = -1436).
    Customers can add data via API, and this data, after inserted, can cause the problem explained above (loop). Therefore I need to find a way to check that these new values don't collide with the existing data in the table.
    One way that currently works is to insert the data, use my pl/sql function to check that there's no loops; if there's a loop, i catch the exception, delete the rows I just inserted, and throw back the error to the user.
    I find it very ugly and unneficient, but I can't find the way to use CONNECT BY with data that is not present in the table. example:
    table my_table contains
    parent_id | child_id
    111 | 777
    777 | 333
    and now customer wants to insert:
    parent_id | child_id
    777 | 111
    Also, if customer wants to insert
    333 | 111
    if I insert the row and run my script, it will work OK, but only if I insert the row. Is there any way to validate this without inserting/removing the row ?
    the script I'm using is similar to the one posted here:
    problems using CONNECT BY
    thanks

    This approach may fail to detect loops introduced by concurrent transactions if one of the transaction uses a serializable isolation level.
    For example, assume there are two sessions (A and B), the table and trigger have been created, and the table is empty. Consider the following scenario.
    First, session A starts a transaction with serializable isolation level:
    A> SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
    Transaction set.Next, session B inserts a row and commits:
    B> INSERT INTO my_table (parent_id, child_id) VALUES (111, 777);
    1 row created.
    B> COMMIT;
    Commit complete.Now, session A successfully inserts a conflicting row and commits:
    A> INSERT INTO my_table (parent_id, child_id) VALUES (777, 111);
    1 row created.
    A> COMMIT;
    Commit complete.
    A> SELECT * FROM MY_TABLE;
    PARENT_ID  CHILD_ID
          111       777
          777       111Session A "sees" the table "as of" a point in time before session B inserted. Also, once session B commits, the lock it acquired is released.
    An alternative approach that would prevent this could use SELECT...FOR UPDATE and a "table of locks" like this:
    SQL> DROP TABLE MY_TABLE;
    Table dropped.
    SQL> CREATE TABLE MY_TABLE
      2  (
      3      PARENT_ID NUMBER,
      4      CHILD_ID NUMBER
      5  );
    Table created.
    SQL> CREATE TABLE LOCKS
      2  (
      3      LOCK_ID INTEGER PRIMARY KEY
      4  );
    Table created.
    SQL> INSERT INTO LOCKS(LOCK_ID) VALUES(123);
    1 row created.
    SQL> COMMIT;
    Commit complete.
    SQL> CREATE OR REPLACE TRIGGER MY_TABLE_AI
      2      AFTER INSERT ON my_table
      3  DECLARE
      4      v_count NUMBER;
      5      v_lock_id INTEGER;
      6  BEGIN
      7      SELECT
      8          LOCK_ID
      9      INTO
    10          v_lock_id
    11      FROM
    12          LOCKS
    13      WHERE
    14          LOCKS.LOCK_ID = 123
    15      FOR UPDATE;
    16         
    17      SELECT
    18          COUNT (*)
    19      INTO  
    20          v_count
    21      FROM  
    22          MY_TABLE
    23      CONNECT BY
    24          PRIOR PARENT_ID = CHILD_ID;
    25 
    26  END MY_TABLE_AI;
    27  /
    Trigger created.Now the scenario plays out like this.
    First, session A starts a transaction with serializable isolation level:
    A> SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
    Transaction set.Next, session B inserts a row and commits:
    B> INSERT INTO my_table (parent_id, child_id) VALUES (111, 777);
    1 row created.
    B> COMMIT;
    Commit complete.Now, when session A tries to insert a conflicting row:
    A> INSERT INTO my_table (parent_id, child_id) VALUES (777, 111);
    INSERT INTO my_table (parent_id, child_id) VALUES (777, 111)
    ERROR at line 1:
    ORA-08177: can't serialize access for this transaction
    ORA-06512: at "TEST.MY_TABLE_AI", line 5
    ORA-04088: error during execution of trigger 'TEST.MY_TABLE_AI'To show that this still handles other cases:
    1. Conflicting inserts in the same transaction:
    SQL> TRUNCATE TABLE MY_TABLE;
    Table truncated.
    SQL> INSERT INTO my_table (parent_id, child_id) VALUES (111, 777);
    1 row created.
    SQL> INSERT INTO my_table (parent_id, child_id) VALUES (777, 111);
    INSERT INTO my_table (parent_id, child_id) VALUES (777, 111)
    ERROR at line 1:
    ORA-01436: CONNECT BY loop in user data
    ORA-06512: at "TEST.MY_TABLE_AI", line 15
    ORA-04088: error during execution of trigger 'TEST.MY_TABLE_AI'2. Read-committed inserts that conflict with previously committed transactions:
    SQL> TRUNCATE TABLE MY_TABLE;
    Table truncated.
    SQL> INSERT INTO my_table (parent_id, child_id) VALUES (111, 777);
    1 row created.
    SQL> COMMIT;
    Commit complete.
    SQL> INSERT INTO my_table (parent_id, child_id) VALUES (777, 111);
    INSERT INTO my_table (parent_id, child_id) VALUES (777, 111)
    ERROR at line 1:
    ORA-01436: CONNECT BY loop in user data
    ORA-06512: at "TEST.MY_TABLE_AI", line 15
    ORA-04088: error during execution of trigger 'TEST.MY_TABLE_AI'3. Conflicting inserts in concurrent, read-committed transactions:
    a) First, empty out the table and start a read-committed transaction in one session (A):
    A> TRUNCATE TABLE MY_TABLE;
    Table truncated.
    A> SET TRANSACTION ISOLATION LEVEL READ COMMITTED;
    Transaction set.b) Now, start a read-committed transaction in another session (B) and insert a row:
    B> SET TRANSACTION ISOLATION LEVEL READ COMMITTED;
    Transaction set.
    B> INSERT INTO my_table (parent_id, child_id) VALUES (111, 777);
    1 row created.c) Now, try to insert a conflicting row in session A:
    A> INSERT INTO my_table (parent_id, child_id) VALUES (777, 111);This is blocked until session B commits, and when it does:
    B> COMMIT;
    Commit complete.the insert in session A fails:
    INSERT INTO my_table (parent_id, child_id) VALUES (777, 111)
    ERROR at line 1:
    ORA-01436: CONNECT BY loop in user data
    ORA-06512: at "TEST.MY_TABLE_AI", line 15
    ORA-04088: error during execution of trigger 'TEST.MY_TABLE_AI'If updates are permitted on the table, then they could cause loops also, but the trigger could be modified to test for this.

  • How to update based on condition during insert on child table

    hi all,
    i have three tables, first table enquiry(enqid, item, type) where all enquiries are entered. after that table bom (bomid, item, enqid, rawmatl) and route (bomid, routeid,routename). in this bom & route are Master Detail table, where entries are made on a later period. the requirement is to update 'type' in enquiry table during insert on Route table.
    for 1 row in bom table there will be more than 5 rows in route table. the condition to update type field in enquiry is, scan the first 5 rows of route table during insert and if routename field contains 'JG' the update type with 'J'. if 'JG' is not there scan the same 5 rows for 'ED' and update type with 'E'. if 'ED' is not there scan for 'CN' and update type with 'C' like this 3 more to test and update.
    thanks in adv. am on 8i
    Kris

    yes, trigger or proc. or package
    any idea how to do this...?

  • How to get multiple rows at one time in a table?

    hi
    I have a JTable bound with ViewObject and i use multiple selection mode setting to get selection row.
    My question is when i select more then one row at one time i only can get those index from JTable but can't get those rows from ViewObject.is it possible to get rows from ViewObject? or how to use JTable row index to get row from ViewObject?

    repost

  • How to extract data from xml and insert into Oracle table

    Hi,
    I have a large xml file. which will have hundreds of the following transaction tags having column names and there values.
    There is a table one of the schema with coulums "actualCostRate","billRate"....etc.
    I need to extract the values of these columns and insert into the table
    <Transaction actualCostRate="0" billRate="0" chargeable="1" clientID="NikuUK" chargeCode="LCOCD1" externalID="L-RESCODE_UK1-PROJ_UK_CNT_GBP-37289-8" importStatus="N" projectID="TESTPROJ" resourceID="admin" transactionDate="2002-02-12" transactionType="L" units="11" taskID="5017601" inputTypeCode="SALES" groupId="123" voucherNumber="ABCVDD" transactionClass="ABCD"/>
    <Transaction actualCostRate="0" billRate="0" chargeable="1" clientID="NikuEU" chargeCode="LCOCD1" externalID="L-RESCODE_US1-PROJ_EU_STD2-37291-4" importStatus="N" projectID="TESTPROJ" resourceID="admin" transactionDate="2002-02-04" transactionType="L" units="4" taskID="5017601" inputTypeCode="SALES" groupId="124" voucherNumber="EEE222" transactionClass="DEFG"/>

    Re: Insert from XML to relational table
    http://www.google.ae/search?hl=ar&q=extract+data+from+xml+and+insert+into+Oracle+table+&btnG=%D8%A8%D8%AD%D8%AB+Google&meta=

  • Read data from E$ table and insert into staging table

    Hi all,
    I am a new to ODI. I want your help in understanding how to read data from an "E$" table and insert into a staging table.
    Scenario:
    Two columns in a flat file, employee id and employee name, needs to be loaded into a datastore EMP+. A check constraint is added to allow data with employee names in upper case only to be loaded into the datastore. Check control is set to flow and static. Right click on the datastore, select control and then check. The rows that have violated the check constraint are kept in E$_EMP+ table.
    Problem:
    Issue is that I want to read the data from the E$_EMP+ table and transform the employee name into uppercase and move the corrected data from E$_EMP+ into EMP+. Please advise me on how to automatically handle "soft" exceptions in ODI.
    Thank you

    Hi Himanshu,
    I have tried the approach you suggested already. That works. However, the scenario I described was very basic. Based on the error logged into the E$_EMP table, I will have to design the interface to apply more business logic before the data is actually merged into the target table.
    Before the business logic is applied, I need to read each row from the E$EMP table first and I do not know how to read from E$EMP table.

  • Conditional Insert into staging table by using sqlloader

    Hi,
    In Oracle apps I'm submitting a concurrent program programmatically which will call sqlloader and insert into a staging a table.
    This table consists of 30 columns.Program has one input parameter.If parameter value = REQUIRED Then it should insert into first three columns of staging table.If it's APPROVED then it should insert into first 10 columns of the same table.
    Data file is pipe delimited file which may or may not have all possible values :For Required,I many not have all three column values

    >
    I think you understood the thinks wrongly. OP marked UTL_FILE as the correct answer, which is again a server side solution.
    >
    Perhaps you failed to notice that the answer now marked correct was posted AFTER mine. I'm not clairvoyant and OP did not state whether a server side or client side solution was appropriate.
    I stand by my comments. Using an external table is an alternative to sql loader but, as I said, simply using an external table instead of sql loader doesn't address OPs problem.
    >
    And IMO, external table will be faster than UTL_FILE
    >
    I'd be more concerned with why OP wants to write a procedure to parse flat files, deal with data conversion errors and perform table inserts when Oracle already provides that functionality using either external tables or sql loader.
    I would suggest loading the file into a new staging table that can hold all of the columns that might be contained in the flat file. Then the appropriate data can be moved to OPs staging table according to the required business rules.
    Sounds like we each think OP should reconsider the architecture.

  • How to show a row has been "removed" from a table

    We maintain rows in a table with a version number which will determine the current set of accounts for a version. I need to be able to show the changes between the versions - when a row was ADDED, REMOVED or there was NO CHANGE. I can work out ADDED and NO_CHANGE without any problem, but I'm not sure how I can determine that a row has been REMOVED when it no longer exists in the next version.
    I have provided an example piece of SQL below:
    with w_acct1 as
    (select 'A1' acct, 0 vers from dual
    union all
    select 'A2' acct, 0 vers from dual
    union all
    select 'A3' acct, 0 vers from dual
    union all
    select 'A1' acct, 1 vers from dual
    union all
    select 'A2' acct, 1 vers from dual
    union all
    select 'A1' acct, 2 vers from dual
    union all
    select 'A4' acct, 2 vers from dual)
    select a.*,
           nvl(lead(acct) over (partition by acct order by vers desc),'NULL') ld,
           case when lead(acct) over (partition by acct order by vers desc) is null then
                   'ADDED'
               when lead(acct) over (partition by acct order by vers desc) = acct then
                   'NO_CHANGE'
               else
                   'REMOVED'
               end add_remove
    from w_acct1 a
    order by vers,acctWhich gives me the following result:
    ACCT VERS LD ADD_REMOVE
    A1     0     NULL     NEW
    A2     0     NULL     NEW
    A3     0     NULL     NEW
    A1     1     A1     NO_CHANGE
    A2     1     A2     NO_CHANGE
    A1     2     A1     NO_CHANGE
    A4     2     NULL     NEW
    The result I want is:
    ACCT VERS LD ADD_REMOVE
    A1     0     NULL     NEW
    A2     0     NULL     NEW
    A3     0     NULL     NEW
    A1     1     A1     NO_CHANGE
    A2     1     A2     NO_CHANGE
    A3     1     NULL     REMOVED
    A1     2     A1     NO_CHANGE
    A2     2     NULL     REMOVED
    A4     2     NULL     NEW
    Note the REMOVED rows associated with the version even though they don't exist in the dataset for that version number.
    Can this be done with analytic functions or some other cool Oracle feature I'm missing?
    Regards
    Richard

    You can't know about a row being removed unless you have a record of that row somewhere, either as a copy of your old data (see example below) or you've recorded the information using delete triggers etc.
    SQL> ed
    Wrote file afiedt.buf
      1  with old_data as (select 1 as id, 'A' as dta from dual union all
      2                     select 2, 'B' from dual union all
      3                     select 3, 'C' from dual)
      4      ,new_data as (select 1 as id, 'A' as dta from dual union all
      5                    select 3, 'X' from dual union all
      6                    select 4, 'Y' from dual)
      7  --
      8      ,ins_upd as (select * from new_data minus select * from old_data)
      9      ,del_upd as (select * from old_data minus select * from new_data)
    10      ,upd as (select id from ins_upd intersect select id from del_upd)
    11      ,ins as (select id from ins_upd minus select id from upd)
    12      ,del as (select id from del_upd minus select id from upd)
    13  --
    14  select 'Inserted' as action, null as old_id, null as old_dta, new_data.id as new_id, new_data.dta as new_dta
    15  from new_data join ins on (ins.id = new_data.id)
    16  union all
    17  select 'Updated', old_data.id, old_data.dta, new_data.id, new_data.dta
    18  from old_data join new_data on (old_data.id = new_data.id)
    19                join upd on (upd.id = new_data.id)
    20  union all
    21  select 'Deleted', old_data.id as old_id, old_data.dta as old_dta, null as new_id, null as new_dta
    22  from old_data join del on (del.id = old_data.id)
    23  union all
    24  select 'No Change' as action, new_data.id as old_id, new_data.dta as old_dta, new_data.id as new_id, new_data.dta as new_dta
    25  from new_data where id not in (select id from ins_upd union all
    26*                                select id from del_upd)
    SQL> /
    ACTION        OLD_ID O     NEW_ID N
    Inserted                        4 Y
    Updated            3 C          3 X
    Deleted            2 B
    No Change          1 A          1 A
    SQL>

  • How to know which row is newly created in the table

    Hi all
    i have one classic table with a button to add new row.
    when page renders initially it displays some record .Here user can either update the previously existing record or may create new ones .
    after adding one more row when users submits it , in back-end i need to go thru all the rows in the view to do some validations .but i need to insert newly created row using API. how can i know which row haas been newly created,
    pls help

    you can know which row is new using different techniques at different places, depending where you want to do it.
    1. In AMImpl: if the PK column attribute of the row does not have a value, then you know this is a new row.
    2. In EOImpl: insertRow will be executed only if it is a new row.
    3. In Pl/SLQ package (if being called from EOImpl): You can check the creation_date or OVN for the row and determine if this is a new row.
    4. You can use the method mentioned in this thread
    Row Status Question
    Thanks
    Tapash

  • How to get selected row from a non-bind ADF table

    Hi,
    I have an ADF table that is based on a collectionModel built programmatically. The collectionModel is this:
    model = new SortableModel(new ArrayList<ArrayList>());
    Hence, it is not a binding table. My question is how to get the selectedRows from a non-bind table.
    I am used to building binding ADF table and I know we can get it from voiterator.getCurrentRow, since the selectionListener is set to the binding....collectionModel.makeCurrent
    <af:table value="#{bindings.ItasLookupTypesVO1.collectionModel}"
    selectedRowKeys="#{bindings.ItasLookupTypesVO1.collectionModel.selectedRow}"
    selectionListener="#{bindings.ItasLookupTypesVO1.collectionModel.makeCurrent}"
    </af:table>
    I am thinking maybe I need to write my own selectionListener, but need more advice/ideas of what's the codes in the customer selection Listener to get it from my SortableModel.
    Please help.
    Thanks
    -Mina

    I'm not sure if this works in your case, but check out the selection listener I write in this blog http://wp.me/pcBZk-eu
    You should use the selection event and check the added set. This should give you access to the selected row.
    Timo

  • How to delete empty row without validation error in ADF Table(EMP)

    Hi Everyone,
    I am using EMP Table in ADF jspx page to insert the data into database.when i insert a row into table by createInsert operation,it inserting the row.But I need to delete that row immediately with out entering any value.
    But it showing some validation error at empno.Is there any ways to delete the empty row?if not,what are the reasons that we can't delete the row.
    could any one tell me the reasons!!
    Thanks in advance!!
    With Best Regards,
    Amar
    Edited by: 973755 on Dec 11, 2012 6:42 AM

    Amar,
    I am little confused with your logic here.....
    but if you are trying to remove the row by clicking Remove button, you can set the immediate property to true and that remove function will run without executing any entity validation.......
    -R

  • How to make a row as selected in output internal table in oops ALV

    Hi All,
    I have ALV grid output using oops ALV concept, in my output i have a checkbox as first column when i select this checkbox and press a push button 'Print' which is there above ALV grid that particular line in output table should get selected and i need to code some logic for printing selected row.
    how to make the particluar row in the output internal table to be selected and where to write the logic for print once it is pressed?
    Thanks in advance
    Srilakshmi.

    but the checkbox is not getting set in internal table when i select some checkboxes.
    can anybody explain y the checkbox in internal table not set?
    Hi Srilakshmi,
    As explained by Uwe, when we change a field ( say check box ) in ALV grid, the view (frontend) changes (showing the tick mark) but the changed data ( normally ) is not transfered to the backend.
    We can initiate this data transfer by just registering the cl_gui_alv_grid=>mc_evt_modified  edit event
      go_grid->set_table_for_first_display( CHANGING  it_fieldcatalog      = pt_fieldcat
                                                      it_outtab            = pt_outtab ).
      go_grid->set_ready_for_input( 1 ).
      go_grid->register_edit_event( EXPORTING i_event_id = cl_gui_alv_grid=>mc_evt_modified ). " This does the trick
    Now as soon as we check a checkbox, the data_changed event is triggered.
    This initiates data transfer to the backend and the checkbox field in internal table is updated.
    check the below code for example.
    DATA: go_cont            TYPE REF TO cl_gui_custom_container,
          go_grid            TYPE REF TO cl_gui_alv_grid,
          gt_fieldcat        TYPE lvc_t_fcat,
          gv_language        TYPE spras VALUE 'E',
          gt_outtab          TYPE TABLE OF bus_loca_demo WITH HEADER LINE.
    START-OF-SELECTION.
      CALL SCREEN 100.
    *       MODULE PBO OUTPUT                                             *
    MODULE pbo OUTPUT.
      SET PF-STATUS 'BASIC'.
      SET TITLEBAR  '001'.
      PERFORM create_and_init_alv CHANGING gt_outtab[]
                                           gt_fieldcat.
    ENDMODULE.                    "pbo OUTPUT
    *       MODULE PAI INPUT                                              *
    MODULE pai INPUT.
      CASE sy-ucomm.
        WHEN 'BACK'.
          SET SCREEN 0. LEAVE SCREEN.
        WHEN 'PRINT'.
          BREAK-POINT.
      ENDCASE.
    ENDMODULE.                    "pai INPUT
    FORM create_and_init_alv CHANGING pt_outtab LIKE gt_outtab[]
                                      pt_fieldcat TYPE lvc_t_fcat.
      CHECK go_cont IS NOT BOUND.
      CREATE OBJECT go_cont
        EXPORTING
          container_name = 'CUSTOM'.
      CREATE OBJECT go_grid
        EXPORTING
          i_parent = go_cont.
      PERFORM build_display_table.
      PERFORM build_fieldcat CHANGING pt_fieldcat.
      go_grid->set_table_for_first_display( CHANGING  it_fieldcatalog      = pt_fieldcat
                                                      it_outtab            = pt_outtab ).
      go_grid->set_ready_for_input( 1 ).
      go_grid->register_edit_event( EXPORTING i_event_id = cl_gui_alv_grid=>mc_evt_modified ). " This does the trick
    ENDFORM.                               "CREATE_AND_INIT_ALV
    FORM build_display_table.
      FREE gt_outtab.
      DO 10 TIMES.
        gt_outtab-creation_partner = sy-index.
        gt_outtab-date_field       = sy-datum.
        APPEND gt_outtab.
      ENDDO.
    ENDFORM.                               "build_display_table
    FORM build_fieldcat CHANGING pt_fieldcat TYPE lvc_t_fcat.
      DATA ls_fcat TYPE lvc_s_fcat.
      CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
        EXPORTING
          i_structure_name = 'BUS_LOCA_DEMO'
        CHANGING
          ct_fieldcat      = pt_fieldcat.
      LOOP AT pt_fieldcat INTO ls_fcat.
        CASE ls_fcat-fieldname.
          WHEN 'CHECKBOX'.
            ls_fcat-checkbox = 'X'.
            ls_fcat-edit     = abap_true.
            MODIFY pt_fieldcat FROM ls_fcat.
          WHEN 'ENTER_FIELD' OR 'DBLCLICK_FIELD'.
            ls_fcat-no_out  = abap_true.
            MODIFY pt_fieldcat FROM ls_fcat.
        ENDCASE.
      ENDLOOP.
    ENDFORM.                               "build_fieldcat
    Cheers,
    Jose.

  • How to identify which data has been inserted  to the table in specific date

    Hi,
    i created one table without data column.. i am inserting data in that table.
    i want which data has been inserted today..
    Please help.
    Thanks,

    If you are in Oracle 10g you can use ORA_ROWSCN.Note that unless the table was created with ROWDEPENDENCIES enabled, though, ORA_ROWSCN is tracked at the block level rather than the row level. So a block with one new row and many old rows could appear as having all been entered today.
    Justin

  • How to see if a data was inserted on a table on a particular date

    Hi,
    I I would like to know how to see if a data was added/removed on a table for a particular date?

    Hello,
    If the table does not have a date field that says when a record was inserted or updated, then you cannot know that information.
    You can fix this by adding that date field to the table.
    You can add a trigger that saves on history table that you need to create, when a record was inserted/updated/deleted.
    Alternatively, you can use Change Data Capture.
    http://blogs.msdn.com/b/manisblog/archive/2008/03/30/sql-server-2008-change-data-capture-part-i.aspx
    Hope this helps.
    Regards,
    Alberto Morillo
    SQLCoffee.com

  • How to delete a row from a SQL Server CE Table with multiple JOINs?

    I want to delete a record from a SQL Server CE table.
    There are 3 tables scripts, options and results. I would like to remove a record from the results table. The where clause contains dynamic information which retrieved via other queries to different tables in the same database. These queries work fine and deliver
    the desired data.
    The Compact server is a clone of a remote table created using the sync framework. The same query to the remote table works fine.
    The error I get is:
    There was an error parsing the query. [ Token line number = 1,Token line offset = 10,Token in error = from ]
    The code that throws the exception is as follows:
    Dim connLoc As SqlCeConnection = New SqlCeConnection(My.Settings.ConnectionString)connLoc.Open()     Dim strDel As String = "Delete r from ResultsTable r inner join OptionsTable o ON o.TestName=r.TestName inner join ScriptTable c ON r.TestName=c.TestName WHERE r.TestName = '" & ds1Loc.Tables(0).Rows(0)(1) & "' AND [Index] = '" & lstIndex & "'"Dim cmdDel As SqlCeCommand = New SqlCeCommandcmdDel.CommandText = strDelcmdDel.Connection = connLoccmdDel.ExecuteNonQuery()
    The values held in ds1Loc.Tables(0).Rows(0)(1) and lstIndex are
    correct so should not be the problem.
    I also tried using parameterised queries
    Dim strDel As String = "Delete r from [ResultsTable] r inner join [OptionsTable] o ON o.TestName=r.TestName inner join [ScriptTable] c ON r.TestName=c.TestName WHERE r.TestName = @TestName AND [Index] = @lstIndex"
    Dim cmdDel As SqlCeCommand = New SqlCeCommand        cmdDel.CommandText = strDel       
    With cmdDel.Parameters           
    .Add(New SqlCeParameter("@TestName", ds1Loc.Tables(0).Rows(0)(1)))           
    .Add(New SqlCeParameter("@lstIndex", lstIndex))       
    End With 
    cmdDel.Connection = connLoc        cmdDel.ExecuteNonQuery()
    I have tried replacing the "=" with "IN" in the the WHERE clause but this has not worked.
    Is it the join that is causing the problem? I can do a select with the same search criteria and joins from the same database.
    Also this query works with SQL Server. Is it perhaps that SQL CE does not support the Delete function the same as SQL Server 2008? I have been looking at this for a while now and cannot find the source of the error. Any help would be greatly appreciated.

    Hello,
    In SQL Server Compact, we can use join in FROM clause. The DELETE statement fail may be caused by the FOREIGN KEY constraint.
    Please refer to:
    DELETE (SQL Server Compact)
    FROM Clause (SQL Server Compact)
    Regards,
    Fanny Liu
    Fanny Liu
    TechNet Community Support

Maybe you are looking for