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
 SQL Server 2005 Forums
 SSIS and Import/Export (2005)
 Excel file

Author  Topic 

collie
Constraint Violating Yak Guru

400 Posts

Posted - 2009-09-21 : 17:00:32
Hi,

I have to import the file in the attachment.
I need to ignore the first few rows. I am only intested in the values starting from row 21 which should be the header row.

How can i read only these rows (from 21) map these columns into a staging table?

Thanks
[url]http://c-haosher.com/file.xls[/url]

Whisky-my beloved dog who died suddenly on the 29/06/06-I miss u so much.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-09-21 : 17:24:17
You can use BULK INSERT or bcp.exe, which both allow you to specify what row to start on. I'm not sure if SSIS provides this capability or not, but I would assume it does. I prefer to do imports/exports via scripts, so that's why lean to BULK INSERT and bcp.exe.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

YellowBug
Aged Yak Warrior

616 Posts

Posted - 2009-09-21 : 18:35:55
You can import data from Excel using the OPENROWSET and select * from [sheet1$] method, without using SSIS.
To specify a range, try "SELECT * FROM [Sheet1$A1:B10]"


In SSIS, in the Excel source object, use 'SQL Command' as the 'Data Access Mode' , and build a query like:
SELECT F4, F5, F6
FROM [Spreadsheet$]
WHERE (F4 <> 'TheHeaderFieldName')

Or you could also try using the conditional split in SSIS to ignore the first few rows.

A quick google found this: http://weblogs.asp.net/mikebosch/archive/2007/10/26/ssis-skipping-rows-and-stripping-subtotals.aspx


AFAIK, BCP and BULK INSERT work with flat files only; not with *.XLS files.
Please correct me - if this is no longer the case.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-09-21 : 22:24:08
With Excel, you can save the file to csv format, which is typically the file format used with bcp.exe and BULK INSERT.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page
   

- Advertisement -