-1

I have spent an hour already on this problem.

I want to dynamically generate columns based on the values from the column AttendanceDate.

I have found some similar questions, but unfortunately the examples were too complicated for me to comprehend.

Data:

enter image description here

Expected output:

enter image description here

5
  • 4
    Google: SQL Server dynamic pivot. Jul 7, 2018 at 14:03
  • 3
    It is a common question... have you tried using other examples from StackOverflow for such a Pivot? For example, here someone asked about columns with names such as "name", "email", "phone"... you would be using your dates, but it doesn't matter because it's dynamic... stackoverflow.com/questions/12210692/t-sql-dynamic-pivot
    – Mike M
    Jul 7, 2018 at 14:07
  • You are just going to be referred to the many many other examples. Try something.. anything.
    – Nick.Mc
    Jul 7, 2018 at 14:45
  • If you don't understand what you've found, show what you have tried so far at least, so we can help you. Any answer we provide would, otherwise, mean you don't understand it either, meaning it's useless to you. Unless you can understand and maintain the code you're provided you shouldn't use it.
    – Thom A
    Jul 7, 2018 at 14:49
  • I kinda gave up on the pivot thing. I just performed multiple queries. The queries are in this order: 1. List of Students 2. All Dates (Distinct) 3. All Statuses Per Student with the date condition. I'll optimize this when I need to. For now, my focus is the prototype. Thanks, everyone. Jul 7, 2018 at 15:22

1 Answer 1

1

This can be done with the stuff method as mention in comments or with a while exists implementation:

http://rextester.com/FPU47008

Not the answer you're looking for? Browse other questions tagged or ask your own question.