Unix Technical Forum

Import cell data from XLS into SQL table

This is a discussion on Import cell data from XLS into SQL table within the SQL Server forums, part of the Microsoft SQL Server category; --> I'm trying to use DTS to import data from an XLS into a SQL table. It works fine in ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-29-2008, 01:32 PM
BigJohnson
 
Posts: n/a
Default Import cell data from XLS into SQL table

I'm trying to use DTS to import data from an XLS into a SQL table.

It works fine in that it INSERT's the data. However, I need it to
UPDATE the table, based upon a ProjectID. Can this be done?

Can a DTS package be fired from a SP using parameters?
Eg UPDATE tProjects SET MyField1=XLS.Sheet1.CellA1,
MyField2=XLS.Sheet2.CellA1 WHERE ProjectID = @ProjectID.

Also, it must handle dynamic XLS file names, eg 981-Budget.xls,
513-Budget.xls, xyz-Budget.xls

Is this the best way to go? Other suggestions most welcome?

Thanks everyone in advance!

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-29-2008, 01:32 PM
Jens
 
Posts: n/a
Default Re: Import cell data from XLS into SQL table


I would do the querying once and put the data in a temporary table:

<SQLCode>
DECLARE @Folder varchar(200)
DECLARE @Filename varchar(200)
DECLARE @Workbook varchar(200)

DECLARE @Sqlstring varchar(4000)

SET @FileName = 'SomeSheet.xls'
SET @Folder = 'C:\SomeFolder\'
Set @Workbook = 'SomeWorkbook'

SET @SQLString = 'SELECT * FROM OpenDataSource(
''Microsoft.Jet.OLEDB.4.0'',''Data Source="' + @Folder + @FileName +
'";User ID=Admin;Password=;Extended properties=Excel 5.0'')...' +
@Workbook

Create Table #SomeTable
(
<YourTableDefinitionhere>
)


INSERt INTO #SomeTable
EXEC(@SQLString)


</Do anything with the data>



</SQLCode>


HTH, Jens Suessmeyer.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-29-2008, 01:32 PM
Jens
 
Posts: n/a
Default Re: Import cell data from XLS into SQL table

Sorry, you also has another question:

"Can a DTS package be fired from a SP using parameters? "

Yes, you have to run the DTSRUn in a cmdshell with XP_cmdshell and hand
over the paramters to global paramerters defined in the DTS package.
(consider the /A switch and look in the BOL for more syntax
information)

HTH, Jens Suessmeyer.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 02:57 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com