I have the following SQL which i want to convert to a stored procedure having dynamic SQL to generate column numbers (1 to 52) for Sale_Week. Also, I want to call this stored procedure from Excel using VBA, passing 2 parameters to stored procedure in SQL Servere.g,DECLARE @KPI nvarchar(MAX) = 'Sales Value with Innovation' DECLARE @Country nvarchar(MAX) = 'UK'I want to grab the resultant pivoted table back into excel. how to do it?USE [Database_ABC]GODECLARE @KPI nvarchar(MAX) = 'Sales Value with Innovation'DECLARE @Country nvarchar(MAX) = 'UK'SELECT [sCHAR],[sCOUNTRY],[Category],[Manufacturer],[Brand],[Description],[1],[2],[3],[4],[5],[6],[7],[ 8 ],[9],[10],[11],[12],[13],[14],[15],[16],[17],[18],[19],[20],[21],[22],[23],[24],[25],[26],[27],[28],[29],[30],[31],[32],[33],[34],[35],[36],[37],[38],[39],[40],[41],[42],[43],[44],[45],[46],[47],[48],[49],[50],[51],[52]FROM (SELECT [sCHAR],[sCOUNTRY],[Category],[Manufacturer],[Brand],[Description],[Sales Value with Innovation],[Sale_Week]FROM [dbo].[ItemTable]WHERE sCOUNTRY='UK' ) AS T PIVOT(SUM([Sales Value with Innovation])for Sale_Week IN ([1],[2],[3],[4],[5],[6],[7],[ 8 ],[9],[10],[11],[12],[13],[14],[15],[16],[17],[18],[19],[20],[21],[22],[23],[24],[25],[26],[27],[28],[29],[30],[31],[32],[33],[34],[35],[36],[37],[38],[39],[40],[41],[42],[43],[44],[45],[46],[47],[48],[49],[50],[51],[52])) AS PTORDER BY PT.SCHAR, PT.sCOUNTRY, PT.Category,PT.Manufacturer, PT.Brand, PT.DescriptionGO
Any help would be most appreciated.Best Rgds.