我有一些 XML 数据需要添加为货币。我尝试的每次转换都会出错
Explicit conversion from data type xml to ____ is not allowed.
这是一个简单的例子,包含了几次失败的尝试。
DECLARE @xmlstuff xml
SET @xmlstuff = '3'
SELECT
CAST (@xmlstuff AS varchar(80)) as worksButDontCare,
--CAST (@xmlstuff AS MONEY) as dollars, -- Explicit conversion from data type xml to money is not allowed.
--CAST (@xmlstuff AS NUMERIC) as number, -- Explicit conversion from data type xml to numeric is not allowed.
--CONVERT (decimal(18,2),@xmlstuff ) AS cd1_feeAmount, -- Explicit conversion from data type xml to decimal is not allowed.
最佳答案
我找到的答案是转换为 varchar 作为中间步骤。
CAST ((CAST (@xmlstuff AS varchar(80))) AS MONEY) AS xmlToVarcharToMoney
关于sql-server - 将 XML 转换成货币,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30279432/