Writing a Query to a file

  • 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!

  • try "sqlcmd" (without the underscore separating sql and cmd)?

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply