retrieve more than one row in one row

  • Hi,

    I have an sql query that retrieves data for some ID where this ID has more than one data related to it.

    Example:

    ID Symbol

    01 A

    01 B

    01 C

    of course the primary key is (ID, Symbol).

    when you select the ID and Symbol, it retieves the previous three rows.

    I need to retrieve these data in one row by concatinating the Symbol to itself; i.e: I need the result to be just like the following:

    ID Symbol

    01 A and B and C

    Is this possible???

  • I have handled this kind of situation in my blog. Please look into it,

    http://venkattechnicalblog.blogspot.com/2008/07/rows-to-columns-in-sql-server.html

    Venkatesan Prabu . J

    Thanks and Regards,
    Venkatesan Prabu, 😛
    My Blog:

    http://venkattechnicalblog.blogspot.com/

  • Hi

    I think venkats solution may not be what you need.

    Try this

    declare @C varchar(100)

    set @C = ''

    select @C = @C + ' And ' + symbol

    from table1 where id = @id

    select @C

    -- final select. substring to remove the first "And"

    select @id,substring(@c,5,len(@c))

    "Keep Trying"

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply