Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2009
    Posts
    2

    Unanswered: How to combine multiple rows into one row

    this is the column in my table name TESTTABLE

    NUMBERS
    --------
    One
    Two
    Three
    One
    Two
    Three
    One
    Two
    Three

    I want them to display DISTINCTLY like this :

    One, Two, Three

    ----------------------------------------------
    I'm new here, hope you can help me with this query. Thank you..

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by bardagul
    I want them to display DISTINCTLY like this :

    One, Two, Three
    why like that?

    would you be happy with results that looked like this --
    One
    Two
    Three
    if not, why not?

    also, are you using an application language like php or asp?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    This can be done in T-SQL, but only as a very last resort. This is really a job for your presentation layer (as Rudy has suggested).
    George
    Home | Blog

  4. #4
    Join Date
    Dec 2008
    Posts
    135
    is this u want
    if ur using 2005 and above versions it will work
    select stuff((select distinct ','+ numbers from testtable for xml path('')),1,1,'')

  5. #5
    Join Date
    Aug 2009
    Posts
    2
    guys.. thank you for all your comment.

    I already solve it on that day, I wrote it like blkr wrote.

    select stuff((select distinct ','+ numbers from testtable for xml path('')),1,1,'')

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •