BCP in TSQL

  • Hi,

    I am using following code for data transfer to flat file:

    declare @sql varchar(8000)

    select @sql = 'bcp demo.scheme.test3 out c:\test20.txt -T -c -t,'

    select @sql

    exec master..xp_cmdshell @sql

    it works fine. However when I change comma seprator to pipe

    declare @sql varchar(8000)

    select @sql = 'bcp demo.scheme.test3 out c:\test20.txt -T -c -t|'

    select @sql

    exec master..xp_cmdshell @sql

    it throws an error:

    The syntax of the command is incorrect.

    Any idea why?

  • I wanted pipe to use pipe as field delimiter instead of comma. However I found the answer. It should be:

    declare @sql varchar(8000)

    select @sql = 'bcp demo.scheme.test4 out c:\test21.txt -T -c -t"|"'

    select @sql

    exec master..xp_cmdshell @sql

    and it runs fine.

    Thanks

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

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