Display Table Fields

  • Hello Friends,

    I've one table where I displayed School Attendance Summary for one month.

    But it is displayed vertically.

    I want to Dispaly it Horizontally and according to date.

    Here Name appears multple times. I want to display it one time only like this.

    Please check the Image for Table Design

    Thanks

  • You may want to have a look at the pivot operator.



    Ole Kristian Velstadbråten Bangås - Virinco - Facebook - Twitter

    Concatenating Row Values in Transact-SQL[/url]

  • hi,

    you can achieve this through pivot here is an example of that

    USE AdventureWorks

    GO

    SELECT [CA], [AZ], [TX]

    FROM

    (

    SELECT sp.StateProvinceCode

    FROM Person.Address a

    INNER JOIN Person.StateProvince sp

    ON a.StateProvinceID = sp.StateProvinceID

    ) p

    PIVOT

    (

    COUNT (StateProvinceCode)

    FOR StateProvinceCode

    IN ([CA], [AZ], [TX])

    ) AS pvt;

    in your case if the class attendencedate is varying then you might have to do it via dynamic sql

    follow this link for that.

    http://beyondrelational.com/blogs/madhivanan/archive/2008/08/27/dynamic-pivot-in-sql-server-2005.aspx

  • Yes here ClassAttendanceDate vary according to months.

  • May using day of month (1-31) be a solution?



    Ole Kristian Velstadbråten Bangås - Virinco - Facebook - Twitter

    Concatenating Row Values in Transact-SQL[/url]

Viewing 5 posts - 1 through 4 (of 4 total)

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