xp_cmdshell output ; separated

  • Hello everyone... again

    Last time i have some issues with getting the xp_cmdshell to give an output. It works fine, however i want the output to the text file to be semi-colon separated. I have tested the following:

    -- To allow advanced options to be changed.

    EXEC sp_configure 'show advanced options', 1;

    GO

    -- To update the currently configured value for advanced options.

    RECONFIGURE;

    GO

    -- To enable the feature.

    EXEC sp_configure 'xp_cmdshell', 1; -- 1 for at enable

    GO

    -- To update the currently configured value for this feature.

    RECONFIGURE;

    GO

    -- Extracting information from the database

    EXEC xp_cmdshell 'bcp "SELECT TcpIpAddress FROM [SIT-DVH].[dbo].[Preb_Idera]" queryout "C:\Output\Ip_outputSemi.txt" -T -c -t;'

    -- To allow advanced options to be changed.

    EXEC sp_configure 'show advanced options', 1;

    GO

    -- To update the currently configured value for advanced options.

    RECONFIGURE;

    GO

    -- To disable the feature.

    EXEC sp_configure 'xp_cmdshell', 0; -- 0 for at disable

    GO

    -- To update the currently configured value for this feature.

    RECONFIGURE;

    GO

    I have seen several places that -t; makes the output to be separated with ; however the output is still:

    xxxxx

    yyyyy

    zzzzzz

    and so on.

  • BCP's -t specifies a field (aka a column) terminator. To specific a row terminator, use -r;.

  • Thank you so much! you are absolutly correct, it works =D

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

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