STRING_AGG aggregation result exceeded the limit of 8000 bytes error

I need to combine texts by group. I found a function called STRING_AGG.

select c.id , c.bereichsname , STRING_AGG(j.oberbereich,',') oberBereiches from stellenangebote_archiv as j join bereiche as c on j.bereich_id = c.id group by c.id, c.bereichsname 

But I am getting the following error:

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

3

2 Answers

Try as below

select c.id , c.bereichsname , STRING_AGG( CAST(j.oberbereich as nvarchar(MAX)),',') oberBereiches from stellenangebote_archiv j join bereiche c on j.bereich_id = c.id group by c.id, c.bereichsname 

So the problem is the length of the concatenated string is exceeding the character limit of the result column.

So we are setting the limit to max by converting all values to "nvarchar(max)" to solve the problem.

And "STRING_AGG()" function returns what it gets.

3

Baris Erden Thanku soo much for the help.. it worked for me

SELECT Employee_Name, STRING_AGG( CAST(Project_Name AS VARCHAR(MAX)), ',') as all_project_names FROM [10.180.0.63].ware_dw.dbo.employee_360 group by Employee_Name; 
0

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like