IamBlossom Posted February 4, 2020 Report Share Posted February 4, 2020 I have this formula that pulls up the record associated by ID, then display in a single line. SELECT CAST(Name AS nvarchar) + N', ' FROM PE_USER_TABLE PE_ID = target.[@field:PE_ID] for xml path(N'') The result is Marco, Mary, Marie, How can I remove the last comma "," ? Thanks! Quote Link to comment Share on other sites More sharing options...
0 cheonsa Posted February 4, 2020 Report Share Posted February 4, 2020 Hi @IamBlossom, What you can do about this is to add the "," before the result. You may try this one: SELECT ABC = STUFF((SELECT ', ' + CAST(Name AS nvarchar) FROM PE_USER_TABLE WHERE PE_ID = target.[@field:PE_ID] FOR XML PATH ('')), 1, 1, '') I am also using the same formula and I am getting my desired output. Cheers! Quote Link to comment Share on other sites More sharing options...
0 Kurumi Posted August 27, 2022 Report Share Posted August 27, 2022 Hi - Just an addition to this, if you would like to display multiple values (comma and quotation marks separated), you can use this formula: STUFF((SELECT ', ' +'"'+ (FIELDNAME) +'"' FROM TABLE_NAME FOR XML PATH ('')), 1, 1, '') Result: "test1.com", "test2.com", "test3.com", "test4.com" Quote Link to comment Share on other sites More sharing options...
Question
IamBlossom
I have this formula that pulls up the record associated by ID, then display in a single line.
SELECT CAST(Name AS nvarchar) + N', ' FROM PE_USER_TABLE PE_ID = target.[@field:PE_ID] for xml path(N'')
The result is Marco, Mary, Marie,
How can I remove the last comma "," ?
Thanks!
Link to comment
Share on other sites
2 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.