Using OPENROWSET
-
Hi I am trying to import a CSVs file using OPENROWSET and import this into a database my problem is the CSV files may contain a varying number of columns i have tried using SELECT BulkColumn FROM OPENROWSET (BULK '\\10.1.2.107\rp_uploaded_files\file.csv', SINGLE_CLOB) MyFile but this puts all the values into one fields i have also tried set @string ='BULK INSERT CSVTest FROM ''\\10.1.2.107\rp_uploaded_files\'+@file+''' WITH (FIELDTERMINATOR = '','',ROWTERMINATOR = ''\n'')' exec (@string) but this requires the destintation table to have the same number of columns as the import file Can anyone advise thanks Simon
-
Hi I am trying to import a CSVs file using OPENROWSET and import this into a database my problem is the CSV files may contain a varying number of columns i have tried using SELECT BulkColumn FROM OPENROWSET (BULK '\\10.1.2.107\rp_uploaded_files\file.csv', SINGLE_CLOB) MyFile but this puts all the values into one fields i have also tried set @string ='BULK INSERT CSVTest FROM ''\\10.1.2.107\rp_uploaded_files\'+@file+''' WITH (FIELDTERMINATOR = '','',ROWTERMINATOR = ''\n'')' exec (@string) but this requires the destintation table to have the same number of columns as the import file Can anyone advise thanks Simon
I would suggest you take a look at the example given at http://syntaxhelp.com/SQLServer/OPENROWSET/CSV[^]