Iulian
Iulian

Reputation: 1200

sql server transpose rows to column value

I have a table that looks like this:

Project | State
----------------
1       | A
2       | A
2       | F
3       | A
3       | F
3       | P
4       | S
5       | C

What i would like to to is get a table like this :

Project | State
----------------
1       | A
2       | AF
3       | AFP
4       | S
5       | C

Is it possible to do this ?

Upvotes: 0

Views: 1131

Answers (1)

Michael Pakhantsov
Michael Pakhantsov

Reputation: 25370

 SELECT Project,
  (SELECT State + ''
   FROM table t
   WHERE t.project = m.project
   FOR XML PATH(''))
 FROM table m
 GROUP BY Project

Upvotes: 2

Related Questions