2 rows of data into 1

  • Hi

    I am having trouble combine 2 rows of data into 1 and was wondering if someone could help me.

    I have a view called "Fees", which contains 4 rows of data as follows,

    ID Description Amount

    1 Registry Fee £10

    1 SM5 £3

    5 DMC £5

    5 Registry Fee £10

    I would like to be able to create another view which groups the data in the "Fees" view depending on the ID so the data will look as follows,

    ID Combined

    1 Registry Fee £10, SM5 £3

    5 DMC £5, Registry Fee £10

    So far I have come up with the following (not sure if it helps).

    DECLARE @STR VARCHAR(100)

    SELECT

    @STR = COALESCE(@str + ', ', '') + [Description]

    FROM Fees

    where

    Fees.ID = '1'

    Print @STR

    Any help will be most appreciated. Thanks

  • Take a look at this post, the concept is the same:

    http://www.sqlservercentral.com/Forums/Topic602485-1291-1.aspx

    If you need help applying this method to your situation, please provide table DDL/sample data as inserts.

    Seth Phelabaum


    Consistency is only a virtue if you're not a screwup. 😉

    Links: How to Post Sample Data[/url] :: Running Totals[/url] :: Tally Table[/url] :: Cross Tabs/Pivots[/url] :: String Concatenation[/url]

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

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