I am trying to write a query to a file with a unique name and pipe "|" delimited. Problem is in 2012 the sp_cmd does not exist and I cant seem to find a solution anywhere that will work. I am currently using the code
set @filepat = 'C:\Temp\'
set @filename = 'test.txt'
set @sqlCommand = 'SQL_CMD -S (local) -E -d SqlAndMe -q "EXEC ExportData" - "' +@filepath + @filename + '" -h-1'
EXEC master..xp_cmdshell @sqlCommand
Any help please urgent!