Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 how to do store procedure dynamically

Author  Topic 

maideen
Starting Member

10 Posts

Posted - 2014-07-08 : 23:37:53
Hi

I have an issue in below stored procedure.
below Store procedure is working fine. But fixed the Year.
Any one know How can do the year dynamically select by user?

SELECT * FROM ( SELECT salesEXE,SalesEXEName,name,gross,YearNo FROM vw_Pivot_Month_ALL) TableYearNo
pivot (Sum(gross) for [year] in ([2008],[2009],[2010],[2011],[2012],[2013],[2014],[2015],[2016],[2017],[2018],[2019],[2020])
)pivotTable

Pls advice

Maideen

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2014-07-09 : 08:54:41
SQL Server does not support dynamic pivoting natively. You can use dynamic pivoting using dynamic SQL - e.g. see this example: http://sqlblogcasts.com/blogs/madhivanan/archive/2008/08/27/dynamic-pivot-in-sql-server-2005.aspx
Go to Top of Page
   

- Advertisement -