Hi @Brian collins ,
Please refer below:
;with cte as(
SELECT primaryGUID, BookName, citation, replace(Titles,' ',' ') Titles,count(citation) count
FROM #temp
GROUP by primaryGUID, BookName, citation,replace(Titles,' ',' ')
)
select primaryGUID, BookName, citation
,STRING_AGG(Titles+'('+cast(count as varchar(10)) +')',' ') Titles
,count(Titles) Titles_count
from cte
group by primaryGUID, BookName, citation
Output:
primaryGUID BookName citation Titles Titles_count
1234-313-13145-94124 Book-1 111.22 Monitoring Data(1) 1
1234-313-13145-94124 Book-1 111.23(a) Monitoring Profiles(2) Monitoring Systems(3) 2
1234-313-13145-94124 Book-1 444.12 Analyze Systems(2) 1
9999-313-13145-94124 Book-2 777.66 Refresh Systems(1) Support Systems(2) 2
9999-313-13145-94124 Book-2 888.99 Refresh Systems(2) 1
Best regards
Melissa
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.