June 15, 2015 at 5:17 am
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.
June 15, 2015 at 6:13 am
ramrajan (6/15/2015)
I have attached SQL File which Gives me the below resultset Excel.xlsxBut 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
Change is inevitable... Change for the better is not.
June 15, 2015 at 8:16 am
Cast and ROUND functions are not working for the Dynamically created PIVOT COlumns
June 29, 2015 at 5:27 am
Any one can you please respond with solution
June 30, 2015 at 9:15 am
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