我有一个存储过程,它返回带有一堆联合的行。我要做的是查看 select 语句是否不产生任何行,如果是,则执行另一个脚本。
这是我在存储过程中使用的当前 sql 选择。请让我知道如何实现这一目标。
SELECT name AS [Name], address1 AS Address1, address2 AS Address2, city AS City, 1 AS DeliveryTypeKey, email AS Email,
( SELECT TOP 1 c_phone_number
FROM phone WITH (NOLOCK)
WHERE value = @value) AS Fax
FROM #Cities x
INNER JOIN prov p WITH (NOLOCK) ON x.ckey = p.pkey
UNION
SELECT name AS [Name], address1 AS Address1, address2 AS Address2, city AS City, 1 AS DeliveryTypeKey, email AS Email,
( SELECT TOP 1 c_phone_number
FROM phone WITH (NOLOCK)
WHERE value = @value) AS Fax
FROM #Cities1 x
INNER JOIN prov1 p WITH (NOLOCK) ON x.ckey = p.pkey
UNION
SELECT name AS [Name], address1 AS Address1, address2 AS Address2, city AS City, 1 AS DeliveryTypeKey, email AS Email,
( SELECT TOP 1 c_phone_number
FROM phone WITH (NOLOCK)
WHERE value = @value) AS Fax
FROM #Cities2 x
INNER JOIN prov2 p WITH (NOLOCK) ON x.ckey = p.pkey