0

I am novice to T-SQL and want to achieve the following in SQL Server 2014:

My source table looks like this.

Col1      Col1       Col2       Col3
------------------------------------
Group1    Val1       Val2       Val3.1
NULL      NULL       NULL       Val3.2
NULL      NULL       NULL       Val3.3
Group2    Val1.2     Value2.2   Val3.4

I want to concatenate based on the First 3 Cols which form a group but has null in the subsequent rows, and the last cols values differ which needs to be concatenated.

The desired result should be following two rows instead of 4:

Col1      Col1       Col2       Col3
------------------------------------
Group1    Val1       Val2       Val3.1,Val3.2,Val3.3
Group2    Val1.2     Value2.2   Val3.4

If is it possible just to create a view or a select query that will do. Please help me as I could not figure this out with my knowledge.

This is not as simple as the other example found in StackOverflow:

ANDY   |  A100
ANDY   |  B391
ANDY   |  X010
TOM    |  A100
TOM    |  A510

My data is more like

ANDY   |  A100
NULL   |  B391
NULL   |  X010
TOM    |  A100
NULL    |  A510
user2693908
  • 109
  • 5

0 Answers0