Below I have shown two tables and also the result table.
How can I get the result table in this manner as I shown on above?
Below I have shown two tables and also the result table.
How can I get the result table in this manner as I shown on above?
SQL Fiddle
You can define a CLR user-defined aggregate to do it. I posted a detailed description of such a solution as an answer to another question - TSQL Comma Separation. There you'll also find a link to a blog post that discusses the problems you may encounter while developing a CLR aggregate.
After you deploy the custom aggregate to the server (I named the function
Concat
but yours may be named differently), you will be able to obtain the required result with the following query: