Click here to Skip to main content
Rate this: bad
good
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 3: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
0 OriginalGriff 464
1 Sergey Alexandrovich Kryukov 429
2 Maciej Los 285
3 CPallini 180
4 Peter Leow 170
0 Sergey Alexandrovich Kryukov 6,971
1 OriginalGriff 5,532
2 Peter Leow 3,997
3 Mika Wendelius 2,850
4 CHill60 2,808


Advertise | Privacy | Mobile
Web04 | 2.8.150224.1 | Last Updated 17 Mar 2013
Copyright © CodeProject, 1999-2015
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