0

I have three rows return from a table as below:

select ID 
from service

Results:

ID 
--
1 
2
3

How can I return output like below:

count  |    IDs 
-------+----------
3      |    1,2,3

2 Answers 2

1

hope this helps

select (select Count(*) from service)+' | '+ SELECT STUFF
(
    (
        SELECT ',' + s.FirstName 
        FROM Employee s
        ORDER BY s.FirstName FOR XML PATH('')
    ),
     1, 1, ''
) AS Employees)
Sign up to request clarification or add additional context in comments.

2 Comments

@apple, mark this as the answer since it answered your question.
@apple Glad i could help
0

If you are going to be work with stuff() function then you will no need to subquery for count of ids

select count(1) count,
       stuff(
             (select ','+cast(id as varchar) from table for xml path('')),
             1,1,'') Ids
from table

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.