1
在SQL Server中,我試圖取代CHAR(0)
與''
,但它不工作作爲我的領域其實是一個NVARCHAR
場,我的整理是Latin1_General_CI_AS
但是當我轉換爲SQL_Latin1_General_CP1_CI_AS
它僅適用於VARCHAR
而不是NVARCHAR
。更換CHAR(0)NVARCHAR Latin1_General_CI_AS整理
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
。
這也許[文章](http://stackoverflow.com/questions/10451684/convert-char-columns-to-nvarchar-按順序改變代碼頁的語言enco)可能是一些幫助:) – bonCodigo