SSIS and Update-Insert(Upsert) based on a SQL Server Result Set

So on a weekly basis, I have to sweep a sub-set of our Member data. So my query is built to produce this result set. I then have to take that result set and compare it to a data table which contains all that same information that I have provided to a 3rd
party vendor. So I need to take into account the following scenarios...
Obviously, if the Member is new, then I have to Insert its row to what we'll call table 3rdPartyMember and create a row out on a 3rdPartyMemberAuditTrail Table
Individually, I also have to manage if any of the following data fields have changed: Name, Birth Date, Addressing Information, Member Plan, Member Termination...and by Individually what I mean is that if the Last Name has changed, then update its row in
3rdPartyMember and Insert a row to 3rdPartyMemberAuditTrail indicating "Last Name Change"...and similarly if Address Line 1 has changed..."Address Line 1 Change"
So I guess my question is this. Should this be done in one whole Stored Procedure invoked by my SSIS Package or should it be done in pieces?
Create the Temporary Table to house our weekly Member subset extract and result set
Determine if the row exists on 3rdPartyMember Table and if it does not, Insert it
If the row exists, determine if there is a First Name Change...Last Name Change...BirthDate change...Address Line 1 change...etc... If there is a change, Update 3rdPartyMember Table and also Insert a row to 3rdPartyMemberAuditTrail indicating the change
Based on all this, I'm just not sure the right way to approach this...meaning should we create one big Stored Procedure to handle everything or each individual data point in my SSIS as an UpSert based on its lookup. I am new to the SSIS World and don't really
know what the generally accepted practice is per se of creating and running an SSIS Package with multiple data point update steps or doing so in one big Stored Procedure.
Also....if anyone know of some good YouTubes or web sites that would instruct me as to how to go about doing this, I'd GREATLY appreciate it.
Thanks for your review and am hopeful for a reply.

In my opinion using SSIS is quite a pain for Upsert-functionality, especially with your requirement of maintaining an audit trail.  With Google you can probably find 20 different variants all of which are quite complex.  I would go for the procedure
version just to keep my sanity.  It is so easy to test and verify.
I have been using an excellent Uppsert add on from Pragmatic Works Task Factory, but that would not help with the audit trail, though...
http://pragmaticworks.com/Products/Features?Feature=UpsertDestination(BatchUpdateOrInsert)
I recently discovered the CHECKSUM-function in Transact-SQL, it might simplify your code and certainly improve performance, if you have lot's of rows.
Here is an example:
create table member
(id int primary key,
name char(10) not null,
address char(20) not null,
checks int not null);
create table member3p
(id int primary key,
name char(10) not null,
address char(20) not null,
checks int not null);
create index xmember3p on member3p(id,checks);
--create member3p_audit (...);
insert into member values(1,'tom','new york',0);
insert into member values(2,'mary','dallas',0);
insert into member values(3,'marvin','durham',0);
update member
set checks = checksum(name,address);
insert into member3p values(1,'tom','new york',0);
insert into member3p values(2,'mary','chicago',0);
update member3p
set checks = checksum(name,address);
insert into member3p
select *
from member m
where not exists
( select *
from member3p m3p
where m3p.id = m.id );
-- insert into audit...
select m.*,
case
when m.name <> m3p1.name then 'x'
else ' '
end as name_change,
case
when m.address <> m3p1.address then 'x'
else ' '
end as adr_change
from member m,
member3p m3p1
where m.id = m3p1.id and
exists
( select *
from member3p m3p2
where m3p2.id = m.id and
m3p2.checks <> m.checks );
-- loop and update member3p and member_audit-- It's OK to update columns that were not changedupdate member3p set name = @new_name, address = @new_address;

Similar Messages

  • Difference between MERGE and Update/Insert

    Can anybody pls tell me what is the difference between MERGE and Update/Insert statements.

    hi vivek,
    merge is totally different than normal update and insert.Merge is a combination of update+inserrt.
    Merge statment first checks the data in your table, if data is already exists then it will try to update the data otherwise it will go for insertion.In case of normal update/insert it will not check the data directly it does the specified operation.
    So based on your requirement you have to select the best option.
    Thanks.

  • In jdbc adapter what is the difference between insert and update insert

    in jdbc adapter what is the difference between insert and update insert
    Edited by: katru vijay on Mar 22, 2010 7:43 AM

    Please refer to this Link [Document Formats for the Receiver JDBC Adapter|http://help.sap.com/saphelp_nw04/Helpdata/EN/22/b4d13b633f7748b4d34f3191529946/frameset.htm]
    Hope this helps.
    Regards,
    Chandravadan

  • Which one is faster loading type between Insert/Update and Update/Insert?

    Hi Gurus,
    Could anyone tell me which loading type faster between Insert/Update and Update/Insert?Any resolution and document reference would be grateful.
    Regards,
    Joni

    910575 wrote:
    Thanks Purvesh for your quick response..
    Yes you are right, we have to prefer sql rather than plsql. But if i have 1 lakh records to be inserted then my insert into select will do insert one by one that mean context switching is more to server i.e 1 lakh.
    If i use BULK COLLECT+ FORALL then in a single switch the lakh records will be inserted right?
    I agree that when we have less number of records to insert we can prefer insert into select, if we have huge data then why not FORALL ?
    You have just tested for 107 records, but in huge data it is different right?
    Thanks,
    VinodYou've misunderstood how it works, I think. When you do the "insert into ... select", Oracle works out what rows need to be inserted and does them in one fell swoop. That's 2 context switches only, with the bulk of the work being done by the SQL engine.
    When you do the BULK COLLECT + FORALL, you're telling Oracle to first identify the rows (that's two context switches straight off; one from PL/SQL to SQL and then back to PL/SQL again), load them into a collection, then loop through the collection and insert the records X rows at a time (which could be all records or whatever you set as the LIMIT on the FORALL) (again, with the context switching between PL/SQL and SQL and back again through each loop).
    Which one sounds like it does the least amount of work? Not the BULK COLLECT, right?

  • Does SSIS guarantee that it loads the data into SQL Server in the same order as it is in Excel

    Hi,
    We are trying to load several Excel files into SQL Server SSIS and we need to save the data in the database in the same order as it is in Excel..
    My question is, Does SSIS guarantee that it loads the data into SQL Server in the same order as it is in Excel. If so, we will add a sequence to ensure we have the order.
    Please advise.
    Thanks & Regards,
    Dhanumjay

    Thanks for your response.
    If it is one file then we can add an index column, but we have to load hundreds of files.
    How adding an index/key column to the table works unless SSIS picks and loads the data in the table in the same order as it is in Excel?
    Just to explain my question better,
    If excel has three rows  {a,b},{c,d},{e,f}, does SSIS ensure it loads the data in the same order in a table.
    Thanks.

  • How to insert data from access to sql server ?

    How to insert data from access to sql server ?
    Please help me
    thanks

    phamtrungkien wrote:
    How to insert data from access to sql server by JAVA?The first four words of my last post:
    masijade wrote:
    JDBC with two connectionsGet a resultset from the jdbc-odbc bridge access connection, cycle through it and add batch insert commands to the jdbc connection to sql server. Give it a try and if the code has an error, then post your code ans ask a question.
    The real question, though, is why you think it absolutely necessary to use Java for this.

  • Convert the insert statement of an MS SQL server into an oracle statement

    Hi ,
    The insert statement in the ms sql server is
    INSERT INTO #temp EXEC Procedurename @Id OUTPUT
    where table temp
    CREATE TABLE #temp(
              Id varchar(10),
              FNa varchar(40),
              LNa varchar(40),
              SId varchar(20),
              Aid varchar(20),
              Did varchar(20),
              CCNa varchar(255),
              CCId int,
              ISu char(1),
              IA char(1),
              Dir char(1),
              Ema varchar(60),
              St char(2),
              DId char(3)
    I converted the insert statement like this
    Procedurename(Id);
    LOOP
    FETCH cv_1 INTO v_temp;
    EXIT WHEN cv_1%NOTFOUND;
    INSERT INTO TEMP VALUES v_temp;
    END LOOP;
    CLOSE cv_1;
    But i am receiving PL/SQL: ORA-00947: not enough values
    Can anyone help on this?
    Thanks

    1) Are you sure that you even need a temp table? Fetching all the rows from a cursor 1-by-1 and then inserting them into a temp table (I'm assuming the Oracle table TEMP is declared as a global temporary table) would seem rather unusual and most likely pointless. In Oracle, readers don't block writers, so there is generally no need to use temp tables to hold intermediate results.
    2) If you do need to store a set of results into a table, it's going to be more efficient to do this in a single SQL statement rather than using a cursor. Something like
    INSERT INTO my_table ( <<list of columns>> )
      SELECT <<list of columns>>
        FROM <<other tables>>
       WHERE <<some conditions>>The SELECT part of the statement here is likely whatever SQL you use in declaring the cursor.
    Justin

  • Role-Based Security In SQL Server Reporting Services

    Hi
    I have created Reports,
    Now I need to assign Role-Based Security, ie like some particular clients can access only some particular report.
    http://localhost/reports/Pages/Folder.aspx
    Here in the above link i can see the property tool bar where i need to set the user assignement roles.
    could any one please help me out how to set different login assigned to a set of report.
    Or is there any tutor links for this.
    Thanks a lot.
    Shan

    Create folders under the Home page (the link you have there).  For each folder set group athentication (AD) or harder managed, user account roles for the folders and the reports under the folder.
    If you set security at that home level you will not be able to control what reports they see or can't see.  You'll need to go all the way to the folder/report level.
    It's also not best practice to deploy reports directly to the home level.  Not best practice in it creating a very hard to manage security level.  Think of the levels in security as such to SQL Server.  Set the connect to sql level, database level and then down to the objects in them.  Same priciples apply to SSRS.
    Here is a cast going through some security settings as well http://technet.microsoft.com/en-us/sqlserver/dd391734.aspx fro creating your roles and utilizing them
    Ted Krueger Blog on lessthandot.com @onpnt on twitter

  • Inserting Data from Oracle to SQL Server on the Real Time Basis.

    Hi Everyone,
    I need to insert data from Oracle to SQL Server on the Real Time basis, we have to fetch data from oracle approx 20 tables, and each table has more than 30 Fields. I need to fetch data in every 15 mins.
    I have created a job using SQL SERVER Agent by writing insert queries for all the tables with conditions that no rows will be inserted which is already in SQL. note that this job is taking only 1 min to execute.
    But in this way our SQL Server getting hanged and it giving problems to other application running in the SQL SERVER.
    So i m requesting all of you that what is the best way to insert huge amount of data on the real time basis.
    Thanx in Advance.

    1) Create Linked server 
    2) insert data using openquery  and set job in sql agent
    3) run job after 15 minutes

  • Is there an easier way to insert date into an MS SQL Server database ?

    Is there an easier way to insert date into an MS SQL Server database without using the DateFormat?

    USe a PreparedStatement and then the method setDate (or setTimestamp )
    http://java.sun.com/docs/books/tutorial/jdbc/basics/prepared.html

  • How to insert chinese data into MS SQL Server 2000 through JDBC

    I am trying to insert chinese data into MS SQL server 2000 using JDBC. how to do this?
    can anybody help me.
    thanx.

    I am trying to insert chinese data into MS SQL server 2000 using JDBC. how to do this?
    can anybody help me.
    thanx.

  • Data comparison and update/insert between two schemas in same database

    Hi all,
    I have requirement like this. In one database, i am having two users, user1 and user2. Both users is having same tables and structure wise also same. In user1, data will be populated by job.
    Now, what i want to do is, i have to find out difference between user1 and user2 data and the Difference data will be updated/inserted into the user2.
    Any ideas please...
    Thanks in advance,
    Pal

    Will trigger help you ... ie. for every update/insert on user1 will do on user2-- it is heavy to do for all table...
    --svmg                                                                                                                                                                                                                                                                   

  • Is pk recommended for update speed and update/insert v merge performance

    Hi there,
    We are looking to merge 50,000 rows or so into a table each day.
    What is generally faster merge or 2 separate sqls (1 to insetrt and 1 to update). Like the merge command but wonder about performance vs the 2 sqls.
    Also with both merge and update is it quicker to try match on a pk or would matching on other unique indexes be just as quick.
    Many Thanks

    Hi,
    What is generally faster merge or 2 separate sqls (1 to insetrt and 1 to update)I would say, if you can do it on one operation, do it. But it should be easy for you to try it out.
    Also with both merge and update is it quicker to try match on a pk or would matching on other unique indexes be just as quickYou aren't really matching on pk, since this is just a constraint. However, all PK constrains are backed by a unique index, so it should be the same.
    But again, try it out
    Regards
    Peter

  • SSIS package give an error if execute through SQL server agent

    I have created a SSIS package in BIDS 2012. If i execute this package through sql server agent it gives the below error:
    Executed as user: NT Service\SQLSERVERAGENT. Microsoft (R) SQL Server Execute Package Utility  Version 11.0.2100.60 for 64-bit  Copyright (C) Microsoft Corporation. All rights reserved.    Started:  11:19:47 AM  Error: 2015-01-20
    11:19:47.83     Code: 0xC0016016     Source: Sub_Hadoop_aggregation      Description: Failed to decrypt protected XML node "DTS:Password" with error 0x8009000B "Key not valid for use in specified state.".
    You may not be authorized to access this information. This error occurs when there is a cryptographic error. Verify that the correct key is available.  End Error  Error: 2015-01-20 11:19:47.94     Code: 0xC0016016     Source:
    Sub_Hadoop_aggregation      Description: Failed to decrypt protected XML node "DTS:Password" with error 0x8009000B "Key not valid for use in specified state.". You may not be authorized to access this information. This error
    occurs when there is a cryptographic error. Verify that the correct key is available.  End Error  Error: 2015-01-20 11:19:48.04     Code: 0xC0016016     Source: Sub_Hadoop_aggregation      Description: Failed to
    decrypt protected XML node "DTS:Password" with error 0x8009000B "Key not valid for use in specified state.". You may not be authorized to access this information. This error occurs when there is a cryptographic error. Verify that the correct
    key is available.  End Error  Error: 2015-01-20 11:19:48.92     Code: 0xC00291EC     Source: alter_keys Execute SQL Task     Description: Failed to acquire connection "mstr_warehouse". Connection may not be
    configured correctly or you may not have the right permissions on this connection.  End Error  DTExec: The package execution returned DTSER_FAILURE (1).  Started:  11:19:47 AM  Finished: 11:19:48 AM  Elapsed:  1.42 seconds.
     The package execution failed.  The step failed.
    so i have change some properties in our package like protectionlevel change from encrypted to dontsavesensitive. After that i have created configuration file for the package and use that configuration file. It executes the package through sql server agent
    smoothly.
    Thanks
    Azhar Khan

    Hi selfdestruct80,
    According to your description, you created SSIS package and it works fine. But you got the error message when the SSIS package was called from a SQL Server Agent job.
    According to my knowledge, the package may not run in the following scenarios:
    The current user cannot decrypt secrets from the package.
    A SQL Server connection that uses integrated security fails because the current user does not have the required permissions.
    File access fails because the current user does not have the required permissions to write to the file share that the connection manager accesses.
    A registry-based SSIS package configuration uses the HKEY_CURRENT_USER registry keys. The HKEY_CURRENT_USER registry keys are user-specific.
    A task or a connection manager requires that the current user account has correct permissions.
    According to the error message, the SSIS Package ProtectionLevel property to EncryptSensitiveWithPassword as ArthurZ mentioned. To solve the problem, you need to go to Command Line tab, manually specify the paassword in SQL Agent Job with the command like below:
    /FILE "\"C:\Users\xxxx\Documents\SQL Server Management Studio\SSIS\Package.dtsx\"" /DECRYPT somepassword /CHECKPOINTING OFF /REPORTING E
    If you have any more questions, please feel free to ask.
    Thanks,
    Wendy Fu
    Wendy Fu
    TechNet Community Support

  • Insertion of data to MS SQL Server is not happening via SOA layer

    Hi,
    There is a requirement in our project to take the data from Orcale EBS and insert into a different legacy and it is a MS SQL Server. So it makes it Orcale DB to SQL Server. When i manually insert data to a table in SQL Server it's working fine. When i try to insert the data to the same table using BPEL(SOA 11g), It's giving out an exeception,
    "{http://schemas.oracle.com/bpel/extension}bindingFault" has been thrown.
    Exception occured when binding was invoked. Exception occured during invocation of JCA binding: "JCA Binding execute of Reference operation 'insert' failed due to: DBWriteInteractionSpec Execute Failed Exception. insert failed. Descriptor name: [InsertCustomerDataHighJump.TRheemImpCustomer]. Caused by com.microsoft.sqlserver.jdbc.SQLServerException: Invalid object name 'DUAL'.. ". The invoked JCA adapter raised a resource exception. Please examine the above error message carefully to determine a resolution. Invalid object name 'DUAL'. 208".
    Any help on this is highly appreciated.
    Thanks,
    Swami

    Hi Vivek,
    I am able to do other operations such as select and update in the SQL server DB. Only insert is giving such a kind of exception.

Maybe you are looking for

  • How to tell if correlation is working...

    All, I currently have a simple BPM where I have 2 receive steps (both start processes) within a 2 branch fork step for a header and item file.  Both receive stepsOnce branch receives the header message and the other receives the item message and ther

  • Error 2343 when installing Photoshop Elements 10

    Error 2343: Specified path is empty. Using Windows 7 (x86)  platform I received the above error message when attempting to reinstall PSE 10.  Wizard did not give any install options but rather 1st attempted to uninstall prior PSE 10 install and fails

  • Async mail to rfc scenario

    hi i receive an xml file vie mail and want to post it with rfc -bapi call into ERP system. The  adapter monitor of the rfc call tells me that he has no communication problems. Each message I try to transfer ends with the following message: Message-Ve

  • When I load PDF DC it takes over my desktop

    all the icons go to pdf and every thing trys to open in pdf

  • Best way to acquire data from both serial port and D/A board in real time?

    In my experiment, I have 2 kinds of data: analog and digital. Now, I have to write a programme to acquire both data not only in real time but also in sychronicity. My colleague tried to write a program for this purpose. However, the digital part was