Garbage In Garbage Out,
Take out the garbage.
The first row is still parsed, and it needs to match the file definition
on col/row terminators.
I get crappy files like this all the time, and in this case, I would
suggest.
Create a table "dbo.Line (col1 line varchar(2000) <-- whatever your max
len is)
Then bulk insert into the one single line, no column delimiter, just a
row delimiter.
Then after the data is in sql, in a single column, you can query to your
hearts content, leaving out the first, row.
Parsing as needed, etc.
Or conceiveably, you could remove the first row, bulk copy back out,
then back in a final time, with the formatted columns.
Dano Smith
-----Original Message-----
From: Nabeel Ahmad
[mailto:mssqldba-ezmlmshield-x59436733.[Email address protected]
Sent: Monday, June 25, 2007 11:38 PM
To: LazyDBA Discussion
Subject: BULK INSERT with firstrow=2
Importance: Low
Hi,
I have a text file and having the header of unwanted columns having less
than the no. of data column in the txt file. I am using the bulk insert
command to insert the text file data into the sql server table by using
the below query:
BULK INSERT Mytable FROM 'e:\Mytext.txt'
WITH
(
FIRSTROW = 2,
FIELDTERMINATOR = ';',
ROWTERMINATOR = '\n'
)
Mytext.txt contains, lets assume like this ---
Name;FName;year;Sex
Robin Singh;Robin;2007;M;Graduate;Working;India
John Mathew;John;1999;M;Post Graduate;Working;USA
Rita Jhonson;Rita;2000;F;Graduate;Housewife;UK
When we are running above query it is inserting from the 3 row i.e. John
Mathew skipping the 2 row. What I come to know from the above result
that if the header has less columns in the txt file then it considers
2nd row as 1st row that's why it's skipping the 2nd row when we are
using above bulk insert.
If there is any solution to insert all the row except header kindly let
me know.
Regards,
Nabeel Ahmad
MASTEK
"Making a valuable difference"
Mastek in NASSCOM's 'India Top 20' Software Service Exporters List.
In the US, we're called MAJESCOMASTEK
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Opinions expressed in this e-mail are those of the individual and not
that of Mastek Limited, unless specifically indicated to that effect.
Mastek Limited does not accept any responsibility or liability for it.
This e-mail and attachments (if any) transmitted with it are
confidential and/or privileged and solely for the use of the intended
person or entity to which it is addressed. Any review, re-transmission,
dissemination or other use of or taking of any action in reliance upon
this information by persons or entities other than the intended
recipient is prohibited. This e-mail and its attachments have been
scanned for the presence of computer viruses. It is the responsibility
of the recipient to run the virus check on e-mails and attachments
before opening them. If you have received this e-mail in error, kindly
delete this e-mail from all computers.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
---------------------------------------------------------------------
TO REPLY TO EVERYBODY , PLEASE CLICK REPLY-ALL, NOT JUST REPLY To post a
dba job: http://jobs.lazydba.com To subscribe : http://www.LazyDBA.com
To unsubscribe: http://www.lazydba.com/unsubscribe.html
MS Sql Server LazyDBA home page