开发者

TSQL QUERY to dump table into a file?

开发者 https://www.devze.com 2023-04-03 11:58 出处:网络
I want to dump a tale into a text file I am using following command - bcp tablename out myTable.dat -T -C

I want to dump a tale into a text file I am using following command -

bcp tablename out myTable.dat -T -C

But got error it says incorrect symbol near bcp.

I am not sure why I am开发者_高级运维 getting this.


From @Code Monkey's Link : http://www.simple-talk.com/sql/database-administration/creating-csv-files-using-bcp-and-stored-procedures/

try this

declare @sql varchar(8000)
select @sql = 'bcp [dbname].[dbo].[tablename] out myTable.dat -c -t, -T -S'+ @@servernameexec 
master..xp_cmdshell @sql

where dbname is the name of your database, and replace dbo with the name of the schema if not dbo

0

精彩评论

暂无评论...
验证码 换一张
取 消