I have a SQL query like this;
SELECT *
FROM Jira.customfieldvalue
WHERE CUSTOMFIELD = 12534
AND ISSUE = 19602
And that's the results;
What I want is; showing in one row (cell) combined all STRINGVALUE
's and they are separated with a comma. Like this;
SELECT --some process with STRINGVALUE--
FROM Jira.customfieldvalue
WHERE CUSTOMFIELD = 12534
AND ISSUE = 19602
Araç Listesi (C2, K1 vb.Belgeler; yoksa Ruhsat Fotokopileri), Min. 5
araç plakası için İnternet Sorgusu, Son 3 Yıla Ait Onaylı Yıl Sonu
Bilanço + Gelir Tablosu, Son Yıl (Yıl Sonuna ait) Detay Mizanı, İçinde
Bulunduğumuz Yıla ait Ara Dönem Geçici Vergi Beyannamesi, Bayi Yorum
E-Maili, Proforma Fatura
How can I do that?
There's a convenient method for this in MySql called GROUP_CONCAT. An equivalent for SQL Server doesn't exist, but you can write your own using the SQLCLR. Luckily someone already did that for you.
Your query then turns into this (which btw is a much nicer syntax):
But please note that this method is good for at the most 100 rows within a group. Beyond that, you'll have major performance problems. SQLCLR aggregates have to serialize any intermediate results and that quickly piles up to quite a lot of work. Keep this in mind!
Interestingly the
FOR XML
doesn't suffer from the same problem but instead uses that horrendous syntax.Using MySQL inbuilt function group_concat() will be a good choice for getting the desired result. The syntax will be -
Before you execute the above command make sure you increase the size of group_concat_max_len else the the whole output may not fit in that cell.
To set the value of group_concat_max_len, execute the below command-
You can change the value 50000 accordingly, you increase it to a higher value as required.
You can achieve this is to combine For XML Path and STUFF as follows:
I believe for databases which support listagg function, you can do:
There are several methods.
If you want just the consolidated string value returned, this is a good quick and easy approach
Which will return your combined string.
You can also try one of the XML methods e.g.