CPDS
CPDS

Reputation: 597

TSQL QUERY to dump table into a file?

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.

Upvotes: 0

Views: 691

Answers (1)

Preet Sangha
Preet Sangha

Reputation: 65496

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

Upvotes: 1

Related Questions