• I'm not sure what you need without DDL, sample data and expected results.

    However, those articles have the basic theory to pivot queries both static and dynamic.

    For more help, please read the article linked on my signature.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2