How to Use pivot function in sql server and then in Lightswitch?
In this post you will know that how can you use sql server pivot
function in visual studio lightswitch. Mainly pivot function is used to convert
rows into columns. Here is an example of school time table with respect to a
particular staff. With this example I will try to explain this concept. We will
insert data row wise and they represent as column wise.
Steps:
1. Insert data row wise from lightswitch screen
Sql Server Entries
2. Create a view that will show these entries as column wise
ALTER view [dbo].[vwTimeTable]
as
select pvt.*
from (
select Day = Day,
TimeID,StaffMa.TecID,
StaffName = StaffMa.Name,
Description= Remarks,
[Time] = Convert(varchar(10), T1.StartTime) + ' to ' +Convert(Varchar(10), T1.EndTime)
from
tbTimeTable) P
pivot
(
Max(P.Time) for P.Day in ([Sunday],[Monday],[Tuseday],[Wednesday],[Thursday],[Friday],[Saturday])
)
as pvt
3. Out Put is like as