OSQL adds a blank space to start of each line of output

  • I am running a simple select statement and exporting the returned data to a text file. The xp_cmdshell and OSQL work fine with the exception that at the start of each line the is a blank space added. Has anyone seen this before? Here are the commands;

    SET @SQLSelect = 'SET NOCOUNT ON SELECT RTRIM(CONVERT(VARCHAR(700), Import)) FROM TABLE WHERE RunID=' + LTRIM(STR(@RunID)) + ' ORDER BY InvoiceNum, LineItem'

    SET @SAPExportFile = 'C:\TEMP\SAPImport_' + @Filedate + '.dat'

    SET @cmd = 'osql -E -S SERVERNAME -d DBNAME -h-1 -w 1029 /Q"' + @SQLSelect + '" /o ' + @SAPExportFile

    EXEC master.dbo.xp_cmdshell @cmd, NO_OUTPUT

  • Hi,

    I'm not sure why OSQL does that, but as far as I know, it always has (?!?).

    Could you not use BCP to get the same resultset to a file without the extraneous space?

    There's also an article about OSQL and it's leading spaces here:

    http://zxat.net/whoami/pgOSQL.aspx

    HTH,



    Ade

    A Freudian Slip is when you say one thing and mean your mother.
    For detail-enriched answers, ask detail-enriched questions...[/url]

  • Thanks for the information and the link. Since we are moving to SQL2005 next week we are going to wait and use SQLCMD. Another reason to move off 2000.

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

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