Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««12

Function to list passenger names? Expand / Collapse
Author
Message
Posted Friday, November 15, 2013 1:21 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Tuesday, March 18, 2014 5:24 AM
Points: 41, Visits: 108
Wow... I am blown away by the support I receive from you guys! You are one smart cookie Lowell! Thanks for enlightening me on this cold evening
Post #1514843
Posted Friday, November 15, 2013 4:56 PM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Today @ 8:01 AM
Points: 1,651, Visits: 5,201
I would suggest something much simpler and probably quicker:

With mySampleData(id,UserName)
AS
(SELECT 1,'James' UNION ALL
SELECT 2,'John' UNION ALL
SELECT 3,'Bob' UNION ALL
SELECT 4,'Kate' UNION ALL
SELECT 5,'Julie'
)
select stuff((select case when row_number() over (order by id desc)=1 then ' and ' else ', ' end + UserName
from mySampleData
order by id
for xml path('')),1,2,'')



MM


  • MMGrid Addin
  • MMNose Addin


  • Forum Etiquette: How to post Reporting Services problems
  • Forum Etiquette: How to post data/code on a forum to get the best help - by Jeff Moden
  • How to Post Performance Problems - by Gail Shaw

  • Post #1514878
    Posted Saturday, November 16, 2013 1:00 PM
    SSC Rookie

    SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

    Group: General Forum Members
    Last Login: Tuesday, March 18, 2014 5:24 AM
    Points: 41, Visits: 108
    Thanks MM, a nice alternative. I have learned a lot about STUFF and FOR XML this week thanks to you guys!
    Post #1514936
    « Prev Topic | Next Topic »

    Add to briefcase ««12

    Permissions Expand / Collapse