When I run:
EXEC MASTER..xp_cmdshell 'bcp [ServerName\Instance].[DB_Name].[dbo].[r] out
"C:\0\folder\subfolder\filename.csv" -c -t "|" -T'
I get the error message:
A valid table name is required for in, out, or format options.
My goal is to simply export the contents of the table named r to a pipe delimited file. The line is used multiple times in the script with a different output file name. The table r is dropped and recreated multiple times with different content each time from a different table (not in a loop or cursor). The error occurs at the first time the code block above is run.
EXEC sp_configure 'show advanced options', 1
EXEC sp_configure 'xp_cmdshell', 1
along with:
RECONFIGURE
I can successfully select and view the table contents with the query:
`Select * From [ServerName\Instance].[DB_Name].[dbo].[r]`
Prior to adding the code [ServerName\Instance]
, the error msg said that it couldn't open a connection.
As @James Z noted you need to specify server_name[\instance_name]
. Also you need to remove [ServerName\Instance].
before [DB_Name]...
Thus, you command should look like this:
EXEC MASTER..xp_cmdshell 'bcp [DB_Name].[dbo].[r] out
"C:\0\folder\subfolder\filename.csv" -c -t "|" -T -S ServerName\Instance'