DECLARE @cmd sysname, @var sysname
SET @var = 'Hello world'
SET @cmd = 'echo ' + @var + ' > C:\var_out.txt'
EXEC master..xp_cmdshell @cmd
Experimenting with the form:
EXEC xp_cmdshell '@echo SELECT [blahblah] FROM [dbo].[masterblah] WHERE [blahIdx] = 1 >> J:\blahOutput.txt'
Alternatives would be great. But ... this should
work (been there, done it before).
And I had done this before. Simple change of the service type. From "NETWORK SERVICES" to "LOCAL SYSTEM".
This can be done in Computer Managment console; "Log on As" tab of the Properties.
The chances are that the problem is just the destination of your file: Vista and above require full admin rights to write or modify any file in the root directory of your boot drive. The user under which SQL server is executing will not have that permission. Change the folder: either to a created folder which as "open" access for all users, or an existing data directory which does.
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)