Dynamic Conversion of PIVOT COLUMNS

  • I have attached SQL File which Gives me the below resultset Excel.xlsx

    But the problem is i am not able to round off the dynamic columns in side my PIVOT any one please help me to rewrite the dynamic query and let me know.

  • ramrajan (6/15/2015)


    I have attached SQL File which Gives me the below resultset Excel.xlsx

    But the problem is i am not able to round off the dynamic columns in side my PIVOT any one please help me to rewrite the dynamic query and let me know.

    Add a CAST to the SELECT list of the dynamic SQL.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Cast and ROUND functions are not working for the Dynamically created PIVOT COlumns

  • Any one can you please respond with solution

  • ramrajan (6/29/2015)


    Any one can you please respond with solution

    Your query from the ZIP file has a number of DECLARE statements where you do the equivalent of:

    DECLARE @somevariable dbo.sometablename

    That will never work, as DECLARE requires a datatype. Thus the query looks like the result of a REPLACE for dynamic SQL where the replacement went bad. It's also somewhat as if you're trying to do dynamic SQL before you actually get to the point of doing actual dynamic SQL. You can't declare a variable and just give it a table name and think that's going to work. You would have to declare it as either varchar or nvarchar and then assign it a value that contains the string with the table name. Referencing that variable can then be done in the construction of the dynamic SQL, but not to help you prepare to create it. Does that make sense?

    Steve (aka sgmunson) 🙂 🙂 🙂
    Rent Servers for Income (picks and shovels strategy)

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply