标签云

微信群

扫码加入我们

WeChat QR Code

This question already has an answer here:

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


Google: SQL Server dynamic pivot.

2018年07月17日10分12秒

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

2018年07月17日10分12秒

You are just going to be referred to the many many other examples. Try something.. anything.

2018年07月17日10分12秒

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.

2018年07月18日10分12秒

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.

2018年07月17日10分12秒