gpt4 book ai didi

sql-server - 将 XML 转换成货币

转载 作者:数据小太阳 更新时间:2023-10-29 02:56:34 26 4
gpt4 key购买 nike

我有一些 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com