在 string_agg 函数内转换为 varchar max

Convert to varchar max inside string_agg function

我有一个 STRING_AGG 函数抛出错误

Error message: STRING_AGG aggregation result exceeded the limit of 8000 bytes. Use LOB types to avoid result truncation.

因为这个 Documentation,说我需要转换为 varchar(max)

当前:

 STRING_AGG(CONCAT([CT].[DeviceType] , ': ' , [COM].[Address]) , ', ')) AS [Contact]

尝试:

STRING_AGG(CONVERT(VARCHAR(MAX),(CONCAT([CT].[DeviceType] , ': ' , [COM].[Address])) , ', ')) AS [Contact]

但是抛出错误:

The STRING_AGG function requires 2 argument(s).

我做错了什么?此致

你把分隔符放在了concat里面,它应该是第二个参数:

STRING_AGG(CONVERT(VARCHAR(MAX),(CONCAT([CT].[DeviceType] , ': ' , [COM].[Address])) ), ', ') AS [Contact]