Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5995929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:01:50+00:00 2026-05-23T00:01:50+00:00

I had a query that returned multiple rows from a table. Then I converted

  • 0

I had a query that returned multiple rows from a table. Then I converted that query to this one:

;with mycte as 
(select s.FirstName + ' ' + s.LastName as Name from ClientStaff cs 
left outer join Staff s on s.Id = cs.StaffId 
left outer join GeneralStatus gs on gs.Id = s.StatusId
 where cs.ClientId = @clientId and gs.Name = 'Active')

 select @staff = (select distinct staff = REPLACE(REPLACE(REPLACE((select Name AS [data()] FROM mycte a 
 order by a.Name for xml path),'</row><row>',', '),'</row>',''),'<row>','') from mycte b)

It returns those rows in a single comma-separated row.
Now I don’t want comma-separated values, instead I want single-line-separated values.
Can anyone tell me if it is possible or not?

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T00:01:51+00:00Added an answer on May 23, 2026 at 12:01 am
    declare @staff varchar(max)
    
    ;with mycte as 
    (
        select distinct s.FirstName + ' ' + s.LastName as Name 
        from ClientStaff cs 
            left outer join Staff s on 
                s.Id = cs.StaffId 
            left outer join GeneralStatus gs on 
            gs.Id = s.StatusId
        where cs.ClientId = @clientId and gs.Name = 'Active'
    )
    select @staff = isnull(@staff + char(13), '') + Name
    from mycte b
    
    print @staff
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I had to delete all the rows from a log table that contained about
I had am maintaining an query that is as follows: select field_1, field_2 from
I have SP that selects data from a table with two columns like this
This is how the query looks like: (simplified) SELECT * FROM posts WHERE user='37'
So really my question is WHY this worked. Anyway, I had this query that
I have the following query (MySQL): SELECT col1, col2 FROM database1.table ->WHERE col3 !=
A while ago I had a query that I ran quite a lot for
I have an ObservableCollection of class Customers that I fill from a database query.
yesterday you had taught me to query record history within a time range here
I'm trying to optimize query performance and have had to resort to using optimizer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.