这是我的SQL查询
DECLARE @Amount int
SELECT @Amount = COALESCE(@Amount+ ', ', '') + Amount FROM Hotel
执行此查询时,我收到错误:
"Conversion failed when converting the varchar value ', ' to data type int"
答案 0 :(得分:7)
您需要显式地将数字转换为字符串,否则它将尝试从字符串到数字进行隐式转换。
同时将变量声明为正确的数据类型...
DECLARE @Amount varchar(max)
SELECT @Amount = COALESCE(@Amount+ ', ', '') + CAST(Amount AS VARCHAR(11))
FROM Hotel
您可能还希望在2008年查看XML PATH
。