how to convert csv file from a table in stored procedure?
I need query for import csv file from a开发者_运维知识库 particular table and that quest must be used inside a stored procedures.
I tried this query
EXEC master..xp_cmdshell
'osql.exe -S ramcobl412 -U connect -P connect
-Q "select * from ramcodb..rct_unplanned_hdr" -o "c:\out.csv" -h-1 -s","'
but that csv file not in format when I open in xsl sheet
Comma separated files are working fine but width is problem
Save the .csv file you want to import to SQL Server on your desktop or some other path you can easily access.
Using SQL Server Management Studio, you should right click the database you want the csv file imported to as a table and go to Tasks > Import Data and use the Import Wizard to import the csv file to a table.
The Import Wizard will automatically account for the different lengths you have for some rows. For example if you have column X and it has 5 characters on 1 row and 10 characters on two other rows the Import Wizard will automatically set the max length for the X column as 10.
精彩评论