Skip to content

Instantly share code, notes, and snippets.

@hoangitk
Forked from ZeusAFK/xp_cmdshell.sql
Last active August 29, 2015 14:20
Show Gist options
  • Save hoangitk/4e0081f72bcf9e3749d8 to your computer and use it in GitHub Desktop.
Save hoangitk/4e0081f72bcf9e3749d8 to your computer and use it in GitHub Desktop.
USE master
GO
EXEC sp_configure 'show advanced options', 1
GO
RECONFIGURE
GO
EXEC sp_configure 'xp_cmdshell', 1
GO
RECONFIGURE
GO
--examples 1
EXEC xp_cmdshell 'ipconfig'
GO
--examples 2
declare @sql varchar(8000)
select @sql = 'bcp "sp_mystore ''2015-01-01'', ''2015-01-31''" queryout D:\Ouput201501.xls -c -t, -T -S'
exec master..xp_cmdshell @sql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment