Combine Multiple rows into 1 row

  • Hi,

    i Have small requirement to convert multiple rows into 1 row

    the input is as folllows

    and the output i need as follows

    key points: premium should be sum off all for each indidiual record,

    Thanks in Advance

    ANjee

  • what rows are you trying to combine and as far as the sum it is

    SELECT ItemName, SUM (Item2) AS "OutPut Name"

    From...

  • Hi Thanks for your reply,

    i'm trying to combine rows with same last name and first name.

    Thanks

    Anjee

  • You can use the GROUP BY for thous

    Select *

    From TableName

    Group By FirstName,LastName

    Or how ever you have the name of the columns =)

  • i think you understood my requirement corrrectly.

    there are two tables

    image 1:shows input

    image 2 :output.

  • There is no direct single T-SQL code that can do this requirement, but u still have a cool code to do it. Please go thro this fantastic article from our Jeff Moden

    The concept : Dynamic Cross Tabs

    The Link : http://www.sqlservercentral.com/articles/Crosstab/65048/

  • If the colum names are the same that you want to combine you can use UNION

    Select ColumnA,ColumnB,ColumnC

    From TableA

    Union

    Select ColumnA,ColumnB,ColumnC

    From TableB

Viewing 7 posts - 1 through 6 (of 6 total)

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