一連のユニオンを含む行を返すストアド プロシージャがあります。私がやろうとしているのは、選択ステートメントが行を生成しないかどうかを確認し、そうであれば別のスクリプトを実行することです。
これは、ストアド プロシージャで使用している現在の 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