简体   繁体   English

SSIS查找转换-SQL查询不起作用

[英]SSIS Lookup Transformation - SQL query not working

I have an SSIS package for deployment into a SQL Server 2012 SSISDB and it uses a Lookup transformation. 我有一个SSIS包,可部署到SQL Server 2012 SSISDB中,它使用查阅转换。 I am using a result from a SQL query to perform the lookup comparison. 我正在使用SQL查询的结果来执行查找比较。

在此处输入图片说明

This does not work and I get all rows as "No matched". 这不起作用,我将所有行都显示为“ No match”。

The query is the following: 查询如下:

DECLARE @LastJobDate DATETIME

SELECT @LastJobDate = COALESCE(MIN(S.LastImportDate), DATEADD(DAY, -2, GETDATE()))
FROM Stations S INNER JOIN    
     Lines L ON S.ID_Line = L.ID_Line
WHERE L.Name LIKE 'lineType%' AND S.ImportData = 1 AND S.Active = 1

SELECT J.ID_Line, J.ID_Job, J.SerialNumber
FROM [Jobs] J INNER JOIN            
     [Lines] L ON J.ID_Line = L.ID_Line
WHERE L.Name LIKE 'lineType%'AND J.TimeStamp >= DATEADD(HOUR, -1, @LastJobDate)

By accident, I found that if I place a [SET NOCOUNT ON] at the beggining of the query, it will work. 偶然地,我发现如果在查询开始时放置一个[SET NOCOUNT ON] ,它将起作用。

DECLARE @LastJobDate DATETIME
SET NOCOUNT ON

SELECT @LastJobDate = COALESCE(MIN(S.LastImportDate), DATEADD(DAY, -2, GETDATE()))
FROM Stations S INNER JOIN    
     Lines L ON S.ID_Line = L.ID_Line
WHERE L.Name LIKE 'lineType%' AND S.ImportData = 1 AND S.Active = 1

SELECT J.ID_Line, J.ID_Job, J.SerialNumber
FROM [Jobs] J INNER JOIN            
     [Lines] L ON J.ID_Line = L.ID_Line
WHERE L.Name LIKE 'lineType%'AND J.TimeStamp >= DATEADD(HOUR, -1, @LastJobDate)

Am I missing something? 我想念什么吗? Why this behavior? 为什么会这样呢?

Why this behavior? 为什么会这样呢?

An SSIS Lookup Component can only consider the first result returned by a multi-statement query such as yours. SSIS查找组件只能考虑由诸如您的多语句查询返回的第一个结果。

When you don't have SET NOCOUNT ON , the first result returned by your query will be the message "1 row(s) affected" or something like that. 当您没有SET NOCOUNT ON ,查询返回的第一个结果将是消息“受影响的1行”或类似的消息。 The Lookup Component will not be able to look at the result set returned by the second half of your query. 查找组件将无法查看查询后半部分返回的结果集。

This is why setting NOCOUNT ON fixes the problem. 这就是为什么将NOCOUNT设置为ON可以解决此问题的原因。 The "row(s) affected" message will not be returned by the first part of the query, and the only thing returned will be the resultset of the second part of the query, which the Lookup Component will then process. 查询的第一部分不会返回“受影响的行”消息,返回的唯一内容将是查询的第二部分的结果集,然后由查询组件进行处理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM