Wednesday, March 7, 2012

how can i import .csv file into database using SQL statement.

i have data with format in .CSV how i can import to databse using SQL statement. and how?
i can import data by change .CSV to .XLS and import .XLS file, but i hvae copy data from .CSv to .XLS it is not good ,so can you show me how to import .CSV file.
i am using SQL2005
thanks for your help

You could use OPENROWSET function with BULK option:

SELECT a.* FROM OPENROWSET( BULK 'c:\test\values.txt',
FORMATFILE = 'c:\test\values.fmt') AS a;

About OPENROWSET: http://msdn2.microsoft.com/en-us/library/ms190312.aspx

About format files: http://msdn2.microsoft.com/en-us/library/ms175915.aspx

No comments:

Post a Comment