• michielbijnen (11/12/2012)


    There is a comma! As far as I know the syntax is correct for the columns variable. Or not?

    every thing in the dynamic sql is correct since the extra "-" is from a comment (you deal with the leading comma a little differently than i would but it works and that is what matters). so now in order to figure out what is going on we are going to need sample data. try running all the queries and make sure you are getting the expected results. Try running SELECT @Columns after you build it and running the base select of your pivot. those are the areas where a problem can occur since the syntax of your dynamic pivot looks fine.


    For faster help in answering any problems Please read How to post data/code on a forum to get the best help - Jeff Moden[/url] for the best way to ask your question.

    For performance Issues see how we like them posted here: How to Post Performance Problems - Gail Shaw[/url]

    Need to Split some strings? Jeff Moden's DelimitedSplit8K[/url]
    Jeff Moden's Cross tab and Pivots Part 1[/url]
    Jeff Moden's Cross tab and Pivots Part 2[/url]