Quantcast
Channel: Microsoft SQL Server
Viewing all articles
Browse latest Browse all 4871

How to concatenate a column if the query result has duplicates of that value?

$
0
0

I want to make a column distinguishable by concatenating it when another column so the user can tell which specific row they are looking at. I want this to only happen for rows that have the same column value as another row, like below.

Dept Building

Accounting Bldg1

Accounting Bldg2

Info Tech Bldg4

Staffing Bldg5

Becomes

Dept Building

Accounting (Bldg1) Bldg1

Accounting (Bldg2) Bldg2

Info Tech Bldg4

Staffing Bldg5

Not the best example.Only the Dept column for Accounting gets concatenated because there is another row with the same Dept, so it gets combined with the Bldg column to make it distinguishable.


Viewing all articles
Browse latest Browse all 4871

Trending Articles



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