December 20, 2007 at 2:39 am
December 20, 2007 at 4:09 am
Can you use a DTS package? iirc, the Excel source allows skipping of rows.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
December 20, 2007 at 5:16 am
December 20, 2007 at 6:11 am
never used this but maybe it helps:
"FIRSTROW = first_row
Specifies the number of the first row to load. The default is 1. This indicates the first row in the specified data file. The row numbers are determined by counting the row terminators.
" (openrowset, BooksOnLine)
December 20, 2007 at 6:56 am
December 20, 2007 at 8:52 am
Import into a staging table, use an Identity to capture the order, delete the items with ID < 5.
Reseed the table each time you do this. (DBCC CHECKIDENT)
December 20, 2007 at 12:45 pm
No, no... it's much easier than any of that. This is a common problem and DTS frequently messes up imports especially if there are some merged cells above the data. Using OpenRowSet, the answer is simple and fast...
I've attached a spreadsheet similar to what the OP has... save it in C:\Temp and then run the following code in Query Analyzer...
SELECT *
FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=C:\Temp\OpenRowSetTest2.xls;HDR=yes',
'SELECT * FROM [Sheet1$a4:c]')
Notice the cell coordinates right next to "Sheet1$" ? The "a4" identifies the left corner of the header row... the "c" identifies the right most column where the data is... and it's intentional that there is no row for the "c" coordinate.
--Jeff Moden
Change is inevitable... Change for the better is not.
December 20, 2007 at 1:00 pm
p.s. Don't forget to close the spreadsheet after you save it or you WILL get an access error... 😉
--Jeff Moden
Change is inevitable... Change for the better is not.
December 20, 2007 at 9:53 pm
May 29, 2008 at 1:33 am
hi..can you post the complete code and nt just the selct query alone
May 29, 2008 at 9:35 am
The rest of the code should be pretty simple to figure out... create a table and use the Select I posted as part of an INSERT/SELECT
--Jeff Moden
Change is inevitable... Change for the better is not.
August 19, 2008 at 1:35 am
I am trying to load the same sample file, it is showing the Error message:
Syntax Error From Class..
Regards,
suresh
August 20, 2008 at 8:42 am
"
much simpler than any of that...
Notice the cell coordinates right next to "Sheet1$" ? The "a4" identifies the left corner of the header row... the "c" identifies the right most column where the data is... and it's intentional that there is no row for the "c" coordinate. "
wunderbar !
August 20, 2008 at 7:32 pm
suresh (8/19/2008)
I am trying to load the same sample file, it is showing the Error message:Syntax Error From Class..
Regards,
suresh
I've never seen such an error in SQL Server, so it must be some GUI code you're trying to write... since I've tested the code I provided before I posted it (like I normally do), and you've not posted your code for us to take a look at, all I can say is watch the quotes, commas, and other punctuation in your embedded code. 😉
--Jeff Moden
Change is inevitable... Change for the better is not.
May 27, 2009 at 8:36 pm
I also encountered this problem and solved it using an inline view:
DECLARE @SKIPROWS INT
SET @SKIPROWS = 4 --SKIP THE FIRST 4 ROWS
SELECT * FROM(
SELECT
ROW_NUMBER () OVER (ORDER BY (SELECT 1 FROM sysobjects WHERE 11)) AS rowNum,*
FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=c:file.xls;HDR=NO;IMEX=1'
,'select * from [sheet1$]')
) as a where rowNum > @SKIPROWS
Viewing 15 posts - 1 through 15 (of 15 total)
You must be logged in to reply to this topic. Login to reply