【问题标题】:How to call .dtsx file which has input parameters from a stored procedure?如何调用具有来自存储过程的输入参数的 .dtsx 文件?
【发布时间】:2019-02-26 20:38:52
【问题描述】:

如何从存储过程中调用带有输入参数的.dtsx包文件?

存储过程 #1 -> 将要导出到 excel 的文件列表作为变量中的逗号分隔值传递。

输入变量将被传递到 SSIS 包以将数据导出到 excel。

如何处理具有来自存储过程调用的输入参数的 SSIS 包?

【问题讨论】:

  • 我认为你有一个了不起的工作答案,为什么不接受它??
  • @goofyui 问题解决了吗?

标签: sql sql-server stored-procedures ssis etl


【解决方案1】:

使用 DtExec 和 xp_cmdshell

一种方法是使用 sql server 中的 xp_cmdshell 实用程序从文件系统运行 DtExec 实用程序。

首先您必须启用xp_cmdshell 实用程序:

-- To allow advanced options to be changed.
EXEC sp_configure 'show advanced options', 1
GO
-- To update the currently configured value for advanced options.
-- WITH OVERRIDE disables the configuration value checking if the value is valid
RECONFIGURE WITH OVERRIDE
GO
-- To enable the xp_cmdshell component.
EXEC sp_configure 'xp_cmdshell', 1
GO
RECONFIGURE WITH OVERRIDE 
GO
-- Revert back the advance option
EXEC sp_configure 'show advanced options', 0
GO 
RECONFIGURE WITH OVERRIDE 
GO

然后你可以使用下面的命令来执行包并传递一个变量值作为参数:

DECLARE @SQLQuery AS VARCHAR(2000)

DECLARE @ServerName VARCHAR(200) = 'ARSHAD-LAPPY' 

SET @SQLQuery = 'DTExec /FILE ^"E:\DataTransfer.dtsx^" '
SET @SQLQuery = @SQLQuery + ' /SET \Package.Variables[ServerName].Value;^"'+ @ServerName + '^"'

EXEC master..xp_cmdshell @SQLQuery
GO

参考文献

有用的链接

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多