|
i.is_disabled, STRING_AGG(c.name, ',') AS column_names |
Our environment contains tables with over 400 columns that have column name lengths of 20 to 100 characters. In our case, the string length was 16,091 characters in one database. This causes the STRING_AGG() function to throw the error: STRING_AGG aggregation result exceeded the limit of 8000 bytes. Use LOB types to avoid result truncation.
To solve here, cast the column name to nvarchar(max) -> STRING_AGG(cast(c.name as nvarchar(max), ',')