执行sql任务定义如下。参数映射是 system:用户名输入varchar 0 -1 系统:packagename输入varchar 1 -1
DECLARE @DataLoaderUsername VARCHAR(100)
DECLARE @PackageName VARCHAR(100)
DECLARE @Code VARCHAR(5)
DECLARE @RunNumber INT
SET @DataLoaderUsername = ?
SET @PackageName = ?
SET @Code = 'bbb'
INSERT INTO tBL_Log
(LoadDateTime,DataLoaderUsername,PackageName,Code)
SELECT GetDate(),@DataLoaderUsername,@PackageName ,@Code
SELECT @RunNumber = Max(RunNumber)
FROM tBL_Log
SELECT @RunNumber As LoadID
显示错误
Execute SQL Task] Error: Executing the query "DECLARE @DataLoaderUsername VARCHAR(100)
在ssms中执行相同的查询,它工作正常(使用硬编码的用户名)
答案 0 :(得分:1)
在每个SQL命令的末尾放置分号。当SSIS将命令发送到SQL Server时,它将其作为单行发送,因此需要使用分号来显示每个新命令开始的SQL Server。
答案 1 :(得分:0)
Your code inside the Execute SQL Task should only contain the following.
INSERT INTO tBL_Log
(LoadDateTime,DataLoaderUsername,PackageName,Code)
SELECT GetDate(),? ,?, 'bbb'
SELECT LoadID = Max(RunNumber)
FROM tBL_Log
In the General page, make sure you have ResultSet
set to single row, and the DB connection also set to a valid connection manager.
I think you've already setup your Parameters
page, just make sure they look like the following. Remember the index for the parameters starts at 0
and is specified in the Parameter Name
box (Not intuitive, I know. It tripped me up in the beginning when I was learning SSIS).
Finally, in order to get the LoadId
value that you are selecting in the last statement, create a variable to hold that value in the ResultSet pane. The ResultSet should be called 0
.
So it looks like this.