在同一台服务器上,我有很少的数据库具有不同的排序规则。 我正在将xml解析为
CREATE TABLE #tblDocuments
(
Document varchar(5) COLLATE DATABASE_DEFAULT
,DocCode varchar(15) COLLATE DATABASE_DEFAULT
,Ammount decimal(18,2)
);
IF @@ERROR <> 0
GOTO ErrorHandl;
INSERT INTO #tblDocuments
(
Document
,DocCode
,Ammount
)
SELECT
Tbl.Col.value('@DocType','varchar(3)') AS Document
,Tbl.Col.value('@DocCode','varchar(15)') AS DocCode
,Tbl.Col.value('@Ammount','decimal(18,2)') AS Ammount
FROM
@xmlData.nodes('/Documents/document') AS Tbl(Col);
有没有办法在不先创建具有预定义排序规则的表的情况下解析xml。像(我知道这段代码不起作用)
SELECT
Tbl.Col.value('@DocType','varchar(3) COLLATE DATABASE_DEFAULT') AS Document
,Tbl.Col.value('@DocCode','varchar(15) COLLATE DATABASE_DEFAULT') AS DocCode
,Tbl.Col.value('@Ammount','decimal(18,2) COLLATE DATABASE_DEFAULT') AS Ammount
INTO #tblDocuments
FROM
@xmlData.nodes('/Documents/document') AS Tbl(Col);enter code here
提前谢谢
答案 0 :(得分:1)
将COLLATE
放在.value()
函数之外:
SELECT
Tbl.Col.value('@DocType','varchar(3)') COLLATE DATABASE_DEFAULT AS [Document]
,Tbl.Col.value('@DocCode','varchar(15)') COLLATE DATABASE_DEFAULT AS [DocCode]
,Tbl.Col.value('@Ammount','decimal(18,2)') AS Ammount
INTO #tblDocuments
FROM
@xmlData.nodes('/Documents/document') AS Tbl(Col);
enter code here
此外,除了字符串数据类型(COLLATE
/ CHAR
/ VARCHAR
/ NCHAR
- 之外,您不会对任何内容使用NVARCHAR
- 甚至已弃用TEXT
和NTEXT
数据类型。)