Empty string field becomes a single space in text file after BCP

  • SET @sqlCommand = 'BCP [database].[dbo].[stored_proc] queryout ' + @filePath + @fileName + ' -c -T -t, "|"'

    BEGIN TRY

    EXEC master..xp_cmdshell @sqlCommand

    END TRY

    I hard coded to '' some values of the fields that will be yielded by the stored_proc and confirmed that they are empty sting ('').

    But when this stored proc is used by the sql job to produce a text file, the empty string values shown in the query editor becomes single space(' ') characters in the text file that is produced.

    Any ideas?

  • As workaround, I set the value to null and it yielded an empty string ('') in the text file. Any other way without forcing it to null value?

  • yaakov.kravitz (5/4/2016)


    As workaround, I set the value to null and it yielded an empty string ('') in the text file. Any other way without forcing it to null value?

    Not quite a workaround.

    It's actually the right way of doing that.

    As far as I know.

    _____________
    Code for TallyGenerator

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

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