Export Pipe Delimited CSV With cmdshell
Enable xp_cmdshell
By default, this feature is disabled.
-- Turns on advanced options and is needed to configure xp_cmdshell
master.dbo.sp_configure 'show advanced options', '1'
RECONFIGURE
-- enable xp_cmdshell
master.dbo.sp_configure 'xp_cmdshell', '1'
RECONFIGUREDisable xp_cmdshell
Recommend to turn off for security after finished your query.
-- Turns on advanced options and is needed to configure xp_cmdshell
master.dbo.sp_configure 'show advanced options', '1'
RECONFIGURE
-- dosable xp_cmdshell
master.dbo.sp_configure 'xp_cmdshell', '0'
RECONFIGURESimple Usage
Example of export all the column data from a specific table. In this example, we use -t"|" to change the delimeter to | instead of default comma ,
Advanced Usage
To extract specific columns, the easier way is to create a new view table and then retrieve from the view.
Reference
Last updated
Was this helpful?