I am trying to concatenate multiple users into a singular string. Here is an example of my database:
dbo.Users
| UserId | AccountId | Title | FirstName | LastName |
| 1234 | 1001 | Mr | John | Banks |
| 1235 | 1001 | Mrs | Georgia | Banks |
| 1236 | 1002 | Mr | Chris | Aims |
| 1237 | 1002 | Mrs | Caroline | Hole |
dbo.Account
| AccountId | SignUpDate | LastLoginDate |
| 1001 | 20/08/2017 | 13/06/2018 |
| 1002 | 20/08/2017 | 13/06/2018 |
I want to be able to get these users in a string like this:
Account 1001:
Mr J & Mrs G Banks
Account 1002:
Mr C Aims & Mrs C Hole
Can anyone make any suggestions?
EDIT:
- The accounts may only have a maximum of 2 users
- The accounts may have a singular user
- The accounts may have any of the following titles: Miss, Mr, Mrs, Ms, Dr, Prof, Major, Bishop, Rev, Sir, Dame, Lord, Capt, Lady
- The accounts should show Title Initial & Title Initial for matching last names
- The accounts should show Title Initial LastName & Title Initial LastName for non-matching last names