Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2006
    Posts
    2

    Unanswered: Record concat display

    We usually do this in SQL Server...

    Code:
    declare @a varchar(100)
    
    select @a = isnull(@a, '') + convert(varchar(10), a) + '-'
    from (  select 1 as a union all
    	select 2 as a union all
    	select 3 as a union all
    	select 4 as a union all
    	select 5 as a 
    	) as tbl
    select @a = left(@a, len(@a) - 1)
    select @a as a
    i want is to display this in a single column with a delimeter. On the below example, it is delimeted with a minus sign.


    How can we do this?


    Result set should be like this...

    select '1-2-3-4-5' as a

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Code:
    select group_concat(a separator '-')
    from (  select 1 as a union all
    	select 2 as a union all
    	select 3 as a union all
    	select 4 as a union all
    	select 5 as a 
    	) as t
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

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