Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88868

How combine multiple cells into a single row in SQL?

$
0
0

I am trying to convert work done MS Excel into t-sql code. Column A is my index. I need to combine the values associate with index =1 in column C, each separated by a soft break.

In MS Excel I achieve this by placing this function in cell C2=IF(A2<>A1,B2,C1 & CHAR(10) & B2) and =IF(A2<>A3,1,0).

enter image description here

The combined functions on column C will concatenate of the values in column B, as the index in column 1 match. The function in column D will compare the values in column C until it finds an unique value. In cell D5, notice values from B2:B5 has been concatenated into a single cell.

If filter the worksheet where the values in column D =1, then I am able to get the desired result.

enter image description here

How can I make this happened in SQL?


Viewing all articles
Browse latest Browse all 88868

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>