SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 SSIS and Import/Export (2008)
 Insert rows
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

sqlfresher2k7
Aged Yak Warrior

609 Posts

Posted - 12/11/2012 :  16:35:51  Show Profile  Reply with Quote
I have requirement to load the data in respective table from the
excel file.

The excel file has status which states the record to added,modify,delete for a employee.

Sample Excel file data

status customerid name city
------ ------------ ------ ------
Add 10000 test SFCO
Modify 10001 test1 NY
Delete 10001 test3 DC



Please let me know know best way to do it.

sunitabeck
Flowing Fount of Yak Knowledge

5155 Posts

Posted - 12/11/2012 :  17:25:42  Show Profile  Reply with Quote
The simplest way I can think of is to load the data from the Excel file into a Work Table and then write a query to Add/modify/delete. To delete the following, and similar code for Insertions and updates
DELETE  y 
FROM YourRealTable y 
WHERE EXISTS
(
	SELECT * FROM YourWorkTable w
	WHERE w.customerid = y.customerid
	AND w.status = 'Delete'
);
You can use SSIS to insert and to run the update queries.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 12/14/2012 :  03:04:42  Show Profile  Reply with Quote
in ssis you can use conditional task to define outputs based on status column value in dataflow task and write corresponding logic (insert/update/delete) in relevant output branches. Use OLEDB command for update and delete and then OLEDB destination for insert.
If number of rows is really huge, consider doing update in update/delete branches to set bit value to indicate records to be deleted/updated and then follow up with execute sql tasks in control to do batch update and deletes. Also for insert set fast load option for OLEDB destination

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000