Click here to Skip to main content
12,504,695 members (57,163 online)
Rate this:
 
Please Sign up or sign in to vote.
My Problem:
my store procedure have dynamic column. so i cannot insert into tabe.
so i need to export directly to excel. Below is my code. Below code is working fine.
i need either export excel directly from store procedure or how can i create dynamic table with store procedure

Pls help me.
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[usp_PIVOT_Seats]
AS
BEGIN
SET NOCOUNT ON;
DECLARE 
    @cols NVARCHAR(MAX),
    @stmt NVARCHAR(MAX)
SELECT @cols = ISNULL(@cols + ', ', '') + '[' + T.showdateformat + ']' FROM 
(SELECT  DISTINCT showdateformat FROM vw_Pivot_Seat_ALL) AS T
 
SELECT @stmt = ' SELECT * FROM vw_Pivot_Seat_ALL AS T
        pivot (SUM(T.Qty)  FOR T.showdateformat IN (' + @cols + ')) AS P'
END
EXEC sp_executesql @STMT=@STMT

Thank you

maideen
Posted 17-Mar-13 2:27am

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Hello,

I will suggest that let this stored procedure return a resultset and use it to create an Excel file. Simplest way will be create a CSV file. Here[^] is some code to get you started.

Regards,
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160919.1 | Last Updated 17 Mar 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100