Character getting changed from , to ?

Padmanabhan, Venkatesh 241 Reputation points
2021-07-14T13:39:50.937+00:00

Hi.
I am using BCP utility to transfer data from SQL table to a delimited file.

Below is the example of the query used:

BCP "SELECT 1 as First, 
quotename(COUNTRY,'""') as COUNTRY, STATUS, QUOTENAME('¸','""') as last  FROM TableName " queryout "path of file" -T -S servername -d DBInstance -b 500 -c -C 65001 -t~

In the query the last character is ¸ - i mean QUOTENAME('¸','""')

But when the file is generated, the last character is coming as ?

what causes the character change while doing a BCP ?

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,786 questions
{count} votes

Accepted answer
  1. Erland Sommarskog 111.1K Reputation points MVP
    2021-07-14T21:54:36.73+00:00

    Keep in mind that BCP runs in the command-line window which uses your OEM code page. So that cedilla is likely to be interpreted as something else, and then it goes downhill from there.

    Change '¸'to nchar(184) to avoid the issue.

    1 person found this answer helpful.
    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Tom Phillips 17,731 Reputation points
    2021-07-14T17:44:57.653+00:00

    How did you view the file to determine the value was ?. That is like a display problem in your viewer and not an output problem from BCP.

    Your viewer is displaying ? because it doesn't know how to display the value 184.

    1 person found this answer helpful.
    0 comments No comments

  2. Cris Zhan-MSFT 6,626 Reputation points
    2021-07-15T07:40:18.08+00:00

    Hi,

    >"SELECT 1 as First,quotename(COUNTRY,'""') as COUNTRY, STATUS, QUOTENAME('¸','""') as last FROM TableName "queryout "path of file"

    When I try to test this sql statement in a database (Chinese_PRC_CI_AS) different from the default server collation (SQL_Latin1_General_CP1_CI_AS), the last character is coming as ? in returned results. Then executed the BCP command to output the data to the file and got the same result.

    I Change '¸' to nchar(184) as Erland suggested, and the problem was solved.

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.