Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
PGG_CA
Starting Member
24 Posts |
Posted - 2012-04-25 : 16:43:10
|
I have the following table. id username name replacement1 userX MrX 02 userY MrY null3 userA MrA 14 userB MsB 3The replacement is an int field and can contain null. What I want to do is return me a concatenated username strings if the user has a replacement. For example, my query should return like this:userXuserYuserA;userXuserB;userAAny help would be appreciated. Thanks. |
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2012-04-25 : 17:00:51
|
SELECT A.UserName+COALESCE(';'+B.UserName,'')FROM myTable ALEFT JOIN myTable B ON A.Replacement=B.ID |
 |
|
|
|
|