April 12, 2010 at 12:30 pm
http://www.tsqltutorials.com/pivot.php
My problem is something related to the above example, i am dynamically pivoting without specifying coloumns and i want to calculate the difference between sales and expenses in the above example and make that as a difference coloumn. Also how can i rename the coloumns after pivoting.
April 12, 2010 at 12:36 pm
I'll give the same advice I always give on the subject of pivoting: Do it in the application, not the database, if it's for presentation to human eyes. Excel, SSRS, Crystal, et al, all do the things you want to do with pivoting, and do it better than T-SQL.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
April 12, 2010 at 12:56 pm
but i am writing a function
April 14, 2010 at 6:17 am
You can't use dynamic SQL in a function (assuming you mean an SQL User-Defined Function).
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply