将数据从商店程序直接导出到excel [英] export data from store procedure into excel directly

查看:90
本文介绍了将数据从商店程序直接导出到excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题:

我的商店程序有动态列。所以我不能插入tabe。

所以我需要直接导出到excel。以下是我的代码。下面的代码工作正常。

i需要直接从商店程序导出excel,或者我如何使用商店程序创建动态表



请帮助我。

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





谢谢



maideen



Thank you

maideen

推荐答案

您好,


我建议让这个存储过程返回一个结果集并用它来创建一个Excel文件。最简单的方法是创建一个CSV文件。这里[ ^ ]是一些可以帮助您入门的代码。



问候,
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,


这篇关于将数据从商店程序直接导出到excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆