Forum Discussion

KarlNixon's avatar
KarlNixon
Copper Contributor
Mar 15, 2021
Solved

Simple View

Hi, am new to SQL and am seeking some support in writing a query.   I have a table of timesheet records (multiple records per day, per employee) which I am looking to summarise into a view by Work ...
  • kodyaz's avatar
    Mar 17, 2021

    Hello KarlNixon

     

    You can use https://www.kodyaz.com/articles/t-sql-pivot-tables-in-sql-server-tutorial-with-examples.aspx structure for your requirement

    Please refer to tutorial for more samples

     

    Here is the SQL query that will help you

     

    select
      *
    from
    (
      select
        Date, Employee, WorkType, Hours
      from EmployeeWork
    ) DataTable
    PIVOT
    (
      SUM(Hours)
      FOR WorkType
      IN (
        [Ordinary],[Leave],[1.5x]
      )
    ) PivotTable

     

     

Resources