Click here to Skip to main content
15,888,263 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to extract the CSV file from SQL server and I manage to do that with the following codes.

SQL
DECLARE @bcpCommand1 VARCHAR(2000) 
SET @bcpCommand1 = 'bcp " SELECT * from ##tblUser " queryout' 
SET @bcpCommand1 = @bcpCommand1 + ' C:\OutPut\CSV\My_Output.csv -c -w -T -S197.1.1.1 -Umyuser -Pmypwd","-CRAW'  

EXEC CPS..xp_cmdshell @bcpCommand1 


But the problem is ...

1)The big integer values are automatically coverted to scientific notation.Instead of this I want to display all the digits as it is.

2)I want to display the date as '01-Dec-2015 11:20 AM'.

3)If any data contains comma then the data is splitted to the next column. for example name is "mohan,Raj" then in the csv data Mohan is in one column and raj in another column.how to avoid that

4) Is there any way extract csv using format file.How to do that?

That is I want to extract to CSV file applied with formatting.

Is there any way to do that.Please help me on this and post the code for that.
Posted

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900