我的问题:我的存储过程有动态列。所以我不能插入表中。所以我需要直接导出到excel。下面是我的代码。下面的代码工作正常。我需要直接从存储过程导出 excel,或者如何使用存储过程创建动态表请帮助我。
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
请帮助我
少女