Write to text file

  • Hi Professionals

    I am trying to write a variable with column headings to a text file but it does not seem to be working and I am not sure where I am going wrong.

    It creates a file called file.txtsoftwaremanufacturer and inside the file is the rest of the parameter 'productname','productversion','licensable'

    here is my code

    alter procedure [dbo].[extractnewheadings]

    @importedquery nvarchar(1000)

    as

    begin

    Declare @sCmd varchar(256)

    --set @importedquery = REPLACE(@importedquery,',', ''',''' );

    --print @importedquery

    SET @sCmd = 'echo > C:\inetpub\wwwroot\cleansed\file.txt' + @importedquery + ''

    exec master..xp_cmdshell @sCmd, no_output

    end

    exec extractnewheadings 'softwaremanufacturer,productname,productversion,licensable'

  • Try this for your command...

    SET @sCmd = 'echo ' + @importedquery + ' > "C:\inetpub\wwwroot\cleansed\file.txt"'

    Also, you should check any such concatenated variables for "DOS Injection" just like you would for "SQL Injection".

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

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

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