Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/performance/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 如果rowcount=0,则返回新查询_Sql_Ssis_Oledb_Rowcount - Fatal编程技术网

Sql 如果rowcount=0,则返回新查询

Sql 如果rowcount=0,则返回新查询,sql,ssis,oledb,rowcount,Sql,Ssis,Oledb,Rowcount,如果我的第一个查询没有返回任何内容,如何返回新查询?我正在使用ssis执行一个存储过程,如果该存储过程没有返回任何内容,它应该传递一个新的查询,然后将该查询保存到一个新的OLEDB目标 示例查询: Declare @DepartureDate DATETIME = '4/16/2013', begin select PassengerNumber,FromTime,ToTime,Remarks from table a where DepartureDate = @DepartureDat

如果我的第一个查询没有返回任何内容,如何返回新查询?我正在使用ssis执行一个存储过程,如果该存储过程没有返回任何内容,它应该传递一个新的查询,然后将该查询保存到一个新的OLEDB目标

示例查询:

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源返回空白查询,而不是IF @ @ RealCube=0提供的新查询。因此,没有数据传输到ole db源。

使用UNION如何


“不存在”可能会快一点:如果不存在,则从表a中选择1,其中DepartureDate=@DepartureDate和UNION ALL更可能快一点。当你可以使用UNION时,千万不要使用UNIONALL@ElectricLlama对,这里没有使用联合的意义。
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)
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