Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Importing Excel file row by row

Author  Topic 

GnR_Slash
Starting Member

14 Posts

Posted - 2009-12-16 : 06:12:07
Hi all,
I am using SQL Server 2005 and .NET 2008 Express

I know how to do this using .net code, but I want to know if there is a "good way" to do it all inside SQL Stored Procedures because of performance.

I have a worksheet with about 30 columns and 5000 rows, and I have a SQL Table where I need to put the data but I don't need all columns from worksheet, just some important columns, lets talk about 10 columns. But my SQL Table have these 10 columns and another fields that are not inside worksheet (user will fill up these new fields later).

Once a day I need to:
1- open excel worksheet
2- get the 1st column (primary key)
3- search this key inside my SQL Table
4- if it does not exists, than I use INSERT
5- if it exists than I use UPDATE

1st question:
Can I make all this inside SQL Server or I still need .net code?

2nd question:
If it is possible, could you give me a link, an example or a tip on how to implement this?

thank you very much!

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2009-12-16 : 06:16:11
I think processing data row by row from excel is tedious..

I have a simple work around for u.

1. Import all the date into a temp_table in sql server.
2. Process the temp_table row by row using cursor or while loop and proceed your business logic.

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-12-16 : 07:08:37
Refer this and modify the query
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=49926

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -