Sumit Rajguru

Sumit Rajguru

  • 1k
  • 405
  • 39.7k

BCP utility on SQL managed instance.

Nov 23 2018 12:26 AM
Hi all,
 
I have a function which returns a table.
 
I am exporting this table to an Excel file using the BCP utility. I want to use this functionality on SQL Managed instance.
 
Declare @Command varchar(2000)
set @Command = 'bcp "select * from ' + @DatabaseName + '.dbo.TableName order by ColumnX" queryout
"D:\Test\' + @DatabaseName +'_TableData.xls" -c -t" " -r"\n" -S Servername -T -S'
EXEC master.dbo.xp_cmdshell @Command
 
kindly suggest me the proper way to achieve this task.
 
All suggestions are appreciated.
Thanks in advance.

Answers (1)