1

SQL Server で置き換えようとしてCHAR(0)''ますが、フィールドが実際にはフィールドであるため機能しません。NVARCHAR照合順序はLatin1_General_CI_AS、変換すると.SQL_Latin1_General_CP1_CI_ASVARCHARNVARCHAR

SELECT val, REPLACE(val , CHAR(0), 'x')
FROM    (
         SELECT 'a' + CHAR(0) + 'b' AS val
        ) AS X

戻り値a | a

SELECT val, REPLACE(CAST(val COLLATE SQL_Latin1_General_CP1_CI_AS AS varchar(100)), CHAR(0), 'x')
FROM    (
         SELECT 'a' + CHAR(0) + 'b' AS val
        ) AS X

戻り値a | axb

SELECT val, REPLACE(CAST(val COLLATE SQL_Latin1_General_CP1_CI_AS AS varchar(100)), CHAR(0), 'x')
FROM    (
         SELECT CAST('a' + CHAR(0) + 'b' AS NVARCHAR(100)) AS val
        ) AS X
SELECT val, REPLACE(CAST(val COLLATE SQL_Latin1_General_CP1_CI_AS AS nvarchar(100)), CHAR(0), 'x')

戻り値a | axb

FROM    (
         SELECT CAST('a' + CHAR(0) + 'b' AS NVARCHAR(100)) AS val
        ) AS X
SELECT val, REPLACE(CAST(val COLLATE SQL_Latin1_General_CP1_CI_AS AS varchar(100)), nCHAR(0), 'x')

戻り値a | a

FROM    (
         SELECT CAST('a' + CHAR(0) + 'b' AS NVARCHAR(100)) AS val
        ) AS X
SELECT val, REPLACE(CAST(val COLLATE SQL_Latin1_General_CP1_CI_AS AS nvarchar(100)), nCHAR(0), 'x')

戻り値a | a

FROM    (
         SELECT CAST('a' + CHAR(0) + 'b' AS NVARCHAR(100)) AS val
        ) AS X

戻り値a | a

0x0000文字を置き換え''て NVARCHAR 状態を失わないようにする方法はありますか

編集: 期待される値はa | axb、最後のクエリ (または類似しているがNVARCHAR.

4

1 に答える 1

2

binary collat​​e 句を使用する必要はありません。CAST

;WITH T
     AS (SELECT CAST('a' + CHAR(0) + 'b' AS NVARCHAR(100)) AS val)
SELECT val,
       REPLACE(val COLLATE Latin1_General_100_BIN, nCHAR(0), 'x')
FROM   T 
于 2012-12-17T14:17:54.110 に答える