Hello
The following example writes the contents of the @var
variable to a file named var_out.txt
in the current server directory:
DECLARE @cmd sysname, @var sysname
SET @var = 'Hello world'
SET @cmd = 'echo ' + @var + ' > var_out.txt'
EXEC master..xp_cmdshell @cmd
Assumptions:
1) this requires, that you have rights to run xp_... procedures -sysadmin role
2) you must enable xp_... to be called :
sp_configure
'Show advanced options','1'
go
RECONFIGURE
go
sp_configure
'xp_cmdshell', '1'
go
RECONFIGURE
go
Kindest Regards,
Damian Widera
SQL Server MVP,
MCT, MCSE Data Platform, MCSD.NET