-1

我有一个运行存储过程的应用程序,它生成动态表单的结果。

许多表格使用相同的过程,然后这些表格将具有不同的列。

我想调用一个存储过程来运行现有的存储过程并将结果转储到服务器上新创建的文档并返回文件的路径。

然后,我可以从 asp 经典程序端生成报告下载链接。

类似以下的内容可能适用于较旧的 sql server 版本。

    EXEC sp_makewebtask 
    @outputfile = 'E:\NMCMS_DEMO\UploadedMedia\Reports\Form.xls', 
    @query ='Select max(case when fe.FLabel = ''Account Number'' then [ItemValue] end) as [Account Number] ,max(case when fe.FLabel = ''Cell Number'' then [ItemValue] end) as [Cell Number] ,max(case when fe.FLabel = ''Comment'' then [ItemValue] end) as [Comment] ,max(case when fe.FLabel = ''E-mail Address'' then [ItemValue] end) as [E-mail Address] ,max(case when fe.FLabel = ''Full Name'' then [ItemValue] end) as [Full Name] ,fs.SessionID FROM  [FormSubmissions]  fs inner join formelements fe on fs.FormID = fe.FID and fe.ID = fs.FormChildID    where FormID = 12 and FType<>4 group by fs.SessionID',
    @colheaders =1, 
    @FixedFont=0,@lastupdated=0,@resultstitle='Testing details'

但是,我不能将我的存储过程与上述方法一起使用。

4

1 回答 1

0
     EXEC sp_configure 'show advanced options', 1
     GO
     -- To update the currently configured value for advanced options.
     RECONFIGURE
     GO
     -- To enable the feature.
     EXEC sp_configure 'xp_cmdshell', 1
     GO
     -- To update the currently configured value for this feature.
     RECONFIGURE   

    create procedure [dbo].[exportSubmissionsReport] 
    @login varchar(50) ='x',
    @password varchar(10) ='y$',
    @Server varchar(50) = 'my/instance', 
    @Database varchar(50) = 'database_DEMO', 
    @Statement varchar(5000),
    @fileName varchar(70) = 'TESD'

    as
    declare @query varchar(8000);
    set @query = 'sqlps.exe -command "invoke-sqlcmd ';
    set @query = @query +@Statement+ ' ';
    set @query = @query + '  -ServerInstance '+@Server+' -Username ';
    set @query = @query + @login+' -Password '+@password+' -Database                     '+@Database+'         |Export-CSV E:\NMCMS_DEMO\UploadedMedia\Reports\'+@fileName+'.csv"';
    execute xp_cmdshell @query
于 2013-06-10T13:57:53.297 回答