Since you're new, let me explain what Phil means by directing you to the first link in my signature line below. It helps others help you both a lot better and a lot more quickly.
Here's another way to provide such readily consumable data (I'm using what you posted as the example).
--===== If the test table already exists, drop it to make reruns in SSMS easier.
-- This is NOT a part of the solution to the provlem. This is how to post test data for the problem.
DROP TABLE IF EXISTS #TestTable
--===== Create and populate the test table on-the-fly.
Once that's done and because you're using SQL Server 2017, we no longer need the XML trick to do this. Instead, we can use the new STRING_AGG() function as follows:
,details = STRING_AGG(details,', ' ) WITHIN GROUP (ORDER BY details)
GROUP BY car,model,engine
ORDER BY car,model,engine
... and that produces the following results...
is pronounced "ree-bar
" and is a "Modenism
" for R
First step towards the paradigm shift of writing Set Based code:
________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.
"Change is inevitable... change for the better is not".
"If "pre-optimization" is the root of all evil, then what does the resulting no optimization lead to?"
How to post code problems
How to Post Performance Problems
Create a Tally Function (fnTally)