Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select All after Row n - How?

Status
Not open for further replies.

LittlBUGer

Programmer
Apr 26, 2006
81
US
Hello. I've recently added the ability for a web tool I'm working on for the user to upload an Excel file to the server and than have the data within be inserted into our SQL Server 2000 database. I have it working with a more bare-bones Excel file in which it uses the SqlBulkCopy statement to select all data from the Excel file into a temp. table and then insert the data from the temp table into the database. The issue is with the Excel file. The template we require has gibberish, or more importantly, text that SQL cannot interpret (nor shouldn't) and thus cannot put into the database on the first 5 rows of the file. Right now, the basic SQL query is just:

Code:
SELECT * FROM blah

Is there a way to select everything after the first 5 rows within the Excel file, or just to skip the top 5 rows? Something like (obviously non working syntax):

Code:
SELECT NOT TOP 5 * FROM blah

OR

SELECT * FROM blah WHERE NOT TOP 5 *

Any suggestions? Thanks.

"Only two things are infinite, the universe and human stupidity, and I'm not sure about the former." - Albert Einstein
 
Try looking into a BULK INSERT statement. You can specify the FIRSTROW to be something other than 1.

Code:
BULK INSERT blah
   FROM 'c:\blahblah.xls'
   WITH (FIRSTROW = 6)

 
I guess I didn't even think of that. I'll give that a try and then let you know. Thanks! :)

"Only two things are infinite, the universe and human stupidity, and I'm not sure about the former." - Albert Einstein
 
I actually figured it out a different way. By slightly modifying the Excel template used, I could use code doing something like:

Code:
SELECT * FROM blah WHERE RowNum > 5

Thanks for the help though. :)

"Only two things are infinite, the universe and human stupidity, and I'm not sure about the former." - Albert Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top