Quantcast
Channel: Forum Getting started with SQL Server
Viewing all articles
Browse latest Browse all 4729

Convert Rows to Column In SQL Server

$
0
0

Dears,

I want to Use Pivot to convert Rows to Column

I have three Tables

1) Student Table with Column (StudentID and StudentName)

2) Subject Table With Column (SubjectID and SubjectName)

3) Student Subject Table With Column (StudentSubjectID , StudentID , SubjectID and Date)

Now i made a query to Get Data from the above Tables

StudentID   StudentName   SubjectID   SubjectName  DateTime  

1                  Yasser                 1               Math               1/1/2017

1                  Yasser                 1               English             1/1/2017

1                  Yasser                 1               Math               3/1/2017

1                  Mark                   1               Math               1/1/2017

1                 John                    1               Math               6/1/2017

Now i will make a monthly report to display Student Subject per month and output will be

Student/Days    1/1/2017      2/1/2017     3/1/2017    4/1/2017  ......................................... 30/1/2017    (All days for month)

Yasser                 Math             -                 Math           -                                               -

                           English             -               -                 -                                               -

Mark                   Math             -                 -                  -                                               -

How can i do this

Thank you


Viewing all articles
Browse latest Browse all 4729

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>