Wednesday, March 7, 2012
Import CSV file into SQL TABLE
i try to import a csv file with tabulation field separator and linefeed as
rowfield.
I've write the following "stored procedure" but it don't import nothing.
My csv file have 41 colums and n rows; the colums is separated by "tab" and
some fields are blank.
Thank you for help!
Gianluca
CREATE PROCEDURE Import
AS
--Step 1: Build Valid BULK INSERT Statement
DECLARE @.SQL varchar(200)
TRUNCATE TABLE table_csv
SET @.SQL = "BULK INSERT table_csv
FROM 'G:\file_csv.dat'
WITH
( FIELDTERMINATOR = '\t' ,
ROWTERMINATOR = '\n' ,
FIRSTROW = 2
)"
--Step 2: Execute BULK INSERT statement
EXEC (@.SQL)
GOHi,
Try executing the BULK INSERT from Query Analyzer or Query Window (SQL
2005). This will through the exact error.
THanks
Hari
SQL Server MVP
"Gianluca Floris" <gianluca.flo_NOSPAM_ris@.tiscali.it> wrote in message
news:45055ce9$0$998$5fc30a8@.news.tiscali.it...
> Hi,
> i try to import a csv file with tabulation field separator and linefeed as
> rowfield.
> I've write the following "stored procedure" but it don't import nothing.
> My csv file have 41 colums and n rows; the colums is separated by "tab"
> and some fields are blank.
> Thank you for help!
> Gianluca
> --
> CREATE PROCEDURE Import
> AS
> --Step 1: Build Valid BULK INSERT Statement
> DECLARE @.SQL varchar(200)
> TRUNCATE TABLE table_csv
> SET @.SQL = "BULK INSERT table_csv
> FROM 'G:\file_csv.dat'
> WITH
> ( FIELDTERMINATOR = '\t' ,
> ROWTERMINATOR = '\n' ,
> FIRSTROW = 2
> )"
> --Step 2: Execute BULK INSERT statement
> EXEC (@.SQL)
> GO
>
> --
>
>
Import CSV file into SQL TABLE
i try to import a csv file with tabulation field separator and linefeed as
rowfield.
I've write the following "stored procedure" but it don't import nothing.
My csv file have 41 colums and n rows; the colums is separated by "tab" and
some fields are blank.
Thank you for help!
Gianluca
--
CREATE PROCEDURE Import
AS
--Step 1: Build Valid BULK INSERT Statement
DECLARE @.SQL varchar(200)
TRUNCATE TABLE table_csv
SET @.SQL = "BULK INSERT table_csv
FROM 'G:\file_csv.dat'
WITH
( FIELDTERMINATOR = '\t' ,
ROWTERMINATOR = '\n' ,
FIRSTROW = 2
)"
--Step 2: Execute BULK INSERT statement
EXEC (@.SQL)
GO
--Hi,
Try executing the BULK INSERT from Query Analyzer or Query Window (SQL
2005). This will through the exact error.
THanks
Hari
SQL Server MVP
"Gianluca Floris" <gianluca.flo_NOSPAM_ris@.tiscali.it> wrote in message
news:45055ce9$0$998$5fc30a8@.news.tiscali.it...
> Hi,
> i try to import a csv file with tabulation field separator and linefeed as
> rowfield.
> I've write the following "stored procedure" but it don't import nothing.
> My csv file have 41 colums and n rows; the colums is separated by "tab"
> and some fields are blank.
> Thank you for help!
> Gianluca
> --
> CREATE PROCEDURE Import
> AS
> --Step 1: Build Valid BULK INSERT Statement
> DECLARE @.SQL varchar(200)
> TRUNCATE TABLE table_csv
> SET @.SQL = "BULK INSERT table_csv
> FROM 'G:\file_csv.dat'
> WITH
> ( FIELDTERMINATOR = '\t' ,
> ROWTERMINATOR = '\n' ,
> FIRSTROW = 2
> )"
> --Step 2: Execute BULK INSERT statement
> EXEC (@.SQL)
> GO
>
> --
>
>
Friday, February 24, 2012
Import Access DB into SQL with OSQL?
I was wondering if there is a way to import an Access database into an MS SQL (MSDE) database using OSQL? I need to write an updater to send out to some customers, that will accomplish this. The Access database and its corresponding SQL database have the same table structure, i just need to update the data. I would like to use OSQL so I can make this process automated, behind the scenes of my GUI updater, for the customer.
I would love to be able to do something like this:
osql -E -Q"IMPORT DATABASE blabla FROM DISK = 'C:\blabla.mdb' WITH REPLACE"
Any ideas? Thanks so much all for looking.
JnuwNo one has a way for me to import an access database through a script or using osql? Help please, thank you all for looking.
import a CSV delimited text file into a table
Hi,
Could you help me to write a script to import a CSV delimited text file into a sql server table.?
Thanks,
carlos
Hi,you can use either a linked server or OPENQUERY for ahhoc querying the data, or the Import wizard of Management Studio. A sample of this would be:
http://p2p.wrox.com/topic.asp?TOPIC_ID=20163
HTH, Jens K. Suessmeyer.
http://www.sqlserver2005.de|||
Thanks Jens, but it is too complex.
I am using BULK INSERT, but now I have a problem when a try to load a DATE value, I get error
Msg 4864, Level 16, State 1, Line 2
Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 1, column 4 (EffectiveDate).
The script is
BULK INSERT grouppolicy
FROM 'C:\datatoload\test.txt'
WITH (
FIELDTERMINATOR = '\t',
ROWTERMINATOR = '\n'
)
Can Somebody help me
Thanks,
Import + ActiveX (cross)
database with the data from the file.
Next, I will write a script to (import) insert from the
temp table to where you want the data to go.
Mary
>--Original Message--
>Hey,
>1)
>I'm doing a lot of importing (by DTS packages) from
commaseparated files
>into tables where i empty/truncate the table _before_
import of ALL info in
>the file.
>BUT - how do I import data from such a file by an UPDATE
command...
>Meaning if the table has an ID col and a NAME col, and
the file has an ID
>col and a NAME col - then I would like to be able to
UPDATE all NAME-cols in
>the table by using the info from the file. The NAME in
the file might have
>changed, but the ID stays the same... Also, i new ID's
are in the file, they
>should be INSERTed into the table (+ the NAME).
>2)
>I have been using ActiveX Data Trans for some imports -
but it would be
>great if I could perform SQL-taks (like above
perhaps...? or is the
>another way) - meaning: how do I make SQL call from
within an ActiveX task?
>
>Any help appreciated - Thanx!
>Best regards
>Jakob H. Heidelberg
>Denmark
>
>
>
>.
>Ah, allright - does somebody have code examples I can use?
Best regards
Jakob
"Mary Lou Friend" <anonymous@.discussions.microsoft.com> skrev i en
meddelelse news:4d9301c402bf$698bdf80$a601280a@.phx.gbl...
> What I will do is create a temporary table in the same
> database with the data from the file.
> Next, I will write a script to (import) insert from the
> temp table to where you want the data to go.
> Mary
>
> commaseparated files
> import of ALL info in
> command...
> the file has an ID
> UPDATE all NAME-cols in
> the file might have
> are in the file, they
> but it would be
> perhaps...? or is the
> within an ActiveX task?