I need help with creating a pivot table. I've already tried many offered solutions here but I am stuck. Hope someone can help. Here's my scenario:
Table1 sample
ID text 2712cb957
document_key text 201808
Table2 sample
ID text 2712cb957
amount_net int 56000
classid int 4021
Table3 (from Table1 and Table2 via inner join ID)
document_key amount_net classid
201808 10 4021
201808 10 4021
201808 15 4023
201808 13 4023
201807 20 4021
201807 15 4021
… … …
Expected pivot table
document_key 4021 4023
201807 35 0
201808 20 28

4021and4023? Or will this be dynamic based on however many distinctclassidexist in your table?{}button at the top of the editor. I've made the edit to this question to do just that.crosstabkeyword, how to apply it, and the steps necessary to make something that is dynamic. It's one of those things where you either dive into functions, or you generate a crosstab/pivot query dynamically and then execute the dynamically generated sql.