如果我的第一个查询没有返回任何内容,如何返回新查询?我正在使用ssis来执行存储过程,如果存储过程没有返回任何内容,它应该传递一个新的查询,然后将其保存到新的ole db目的地。
示例查询:
Declare @DepartureDate DATETIME = '4/16/2013',
begin
select PassengerNumber,FromTime,ToTime,Remarks from table a where DepartureDate = @DepartureDate
if (@@ROWCOUNT = 0)
begin
Select
'-' [PassengerNumber],
'00:00' [FromTime],
'00:00' [ToTime],
'No Mismatch' [Remarks]
end
End
我的问题是我的ole db source返回空查询而不是if(@@ rowcount = 0)提供的新查询。因此没有数据传输到ole db源。
答案 0 :(得分:1)
如何使用UNION
?
SELECT PassengerNumber, FromTime, ToTime, Remarks
FROM tableA
WHERE DepartureDate = @DepartureDate
UNION ALL
SELECT '-' [PassengerNumber],
'00:00' [FromTime],
'00:00' [ToTime],
'No Mismatch' [Remarks]
WHERE 0 = (SELECT COUNT(*) FROM tableA WHERE DepartureDate = @DepartureDate)
答案 1 :(得分:1)
DECLARE @count INT = -1;
SELECT @count = COUNT(*)FROM TABLE a;
IF (@count > 0)
BEGIN
SELECT PassengerNumber,FromTime,ToTime,Remarks FROM TABLE a;
END
ELSE
SELECT
'-' [PassengerNumber],
'00:00' [FromTime],
'00:00' [ToTime],
'No Mismatch' [Remarks];
END
END