SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


««123»»

Using OPENROWSET to import CSV files Expand / Collapse
Author
Message
Posted Friday, November 06, 2009 2:23 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, November 11, 2009 1:49 AM
Points: 13, Visits: 27
Hi

i have tried using BULK INSERT

using

set @string ='BULK INSERT CSVTest FROM ''\\10.1.2.107\rp_uploaded_files\'+@file+''' WITH (FIELDTERMINATOR = '','',ROWTERMINATOR = '''')'
exec (@string)

but this requires the destintation table to have the same number of columns as the import file

The files i want to import have an unknown number of coulmns

Can you help at all?

Simon
Post #814762
Posted Friday, November 06, 2009 6:39 AM
SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 2:36 PM
Points: 7,848, Visits: 4,296
Simon Parry (11/6/2009)
Hi

yes im using a 64bit sever

im having trouble locating to odbc drivers for this and can only find 32bit


can you point me in the right direction

thanks

simon

http://www.microsoft.com/downloads/details.aspx?FamilyID=000364db-5e8b-44a8-b9be-ca44d18b059b&displaylang=en


- GSquared

"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
Post #814891
Posted Friday, November 06, 2009 10:52 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, November 11, 2009 1:49 AM
Points: 13, Visits: 27
Hi thanks for that

unfortunately i still get the same error

sorry if im missing something here

can you help?

thank you

simon
Post #815082
Posted Friday, November 06, 2009 11:14 AM
SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 2:36 PM
Points: 7,848, Visits: 4,296
If you have the driver correctly installed, then the error is most likey to be from not having the correct filename and/or path in the openrowset command.

- GSquared

"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
Post #815098
Posted Friday, November 06, 2009 9:18 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 4:00 PM
Points: 18,349, Visits: 12,359
Simon Parry (11/6/2009)
Hi

i have tried using BULK INSERT

using

set @string ='BULK INSERT CSVTest FROM ''\\10.1.2.107\rp_uploaded_files\'+@file+''' WITH (FIELDTERMINATOR = '','',ROWTERMINATOR = '''')'
exec (@string)

but this requires the destintation table to have the same number of columns as the import file

The files i want to import have an unknown number of coulmns

Can you help at all?

Simon


Yep... attach a copy of one of the files (unless it has private info in it) to your next post and tell me what you think you'd like to do with it.


--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

For better, quicker answers, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/

For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Post #815296
Posted Friday, November 06, 2009 9:51 PM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 3:52 PM
Points: 2,086, Visits: 2,075
Please also consider using an SSIS package to import data from files to a database - that is its primary purpose in life, and I don't like to see a good tool get upset.


The quality of the answers is directly proportional to the quality of the question.
Post #815309
Posted Tuesday, November 10, 2009 6:39 AM
SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 2:36 PM
Points: 7,848, Visits: 4,296
Paul White (11/6/2009)
Please also consider using an SSIS package to import data from files to a database - that is its primary purpose in life, and I don't like to see a good tool get upset.

SSIS requires a fixed number of columns in the import definition.


- GSquared

"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
Post #816443
Posted Tuesday, November 10, 2009 3:33 PM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 3:52 PM
Points: 2,086, Visits: 2,075
GSquared (11/10/2009)
SSIS requires a fixed number of columns in the import definition.

Well it certainly prefers to deal with stable metadata, that's for sure. But, unless the requirement is actually to import a file with truly 'any structure' into an unspecified table, there's often a way around it.

Most frequently I've come across this as different files being subsets of a larger structure, or something like that. If there's some structure or logical to work with, it's often possible to do.



The quality of the answers is directly proportional to the quality of the question.
Post #816889
Posted Tuesday, November 10, 2009 3:53 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 4:00 PM
Points: 18,349, Visits: 12,359
Jeff Moden (11/6/2009)
Simon Parry (11/6/2009)
Hi

i have tried using BULK INSERT

using

set @string ='BULK INSERT CSVTest FROM ''\\10.1.2.107\rp_uploaded_files\'+@file+''' WITH (FIELDTERMINATOR = '','',ROWTERMINATOR = '''')'
exec (@string)

but this requires the destintation table to have the same number of columns as the import file

The files i want to import have an unknown number of coulmns

Can you help at all?

Simon


Yep... attach a copy of one of the files (unless it has private info in it) to your next post and tell me what you think you'd like to do with it.


Simon?


--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

For better, quicker answers, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/

For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Post #816903
Posted Tuesday, November 10, 2009 7:35 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, November 11, 2009 1:49 AM
Points: 13, Visits: 27
Hi

Sorry for the delay

I have attached 3 sample files, its possible each one of these may be used

If the files were the same size each time i could do it, but because they have a varying number of columns im stuck


Many thanks for all your help

Simon


  Post Attachments 
sample3.zip (3 views, 733 bytes)
Post #816944
« Prev Topic | Next Topic »

««123»»

Permissions Expand / Collapse