我只是设置了一个 SQL 存储过程以特定顺序(从重要到不重要)返回特定行:
-- 1st Level -> Query a more detailed object...
SELECT ... WHERE something
-- if a result is find, the SP is returning the correct row.
-- if rowcount = 0 then, the SP is returning an empty row
-- and continues with the next query (less specific than the 1st one).
IF @@ROWCOUNT = 0
BEGIN
SELECT .... WHERE something else...
-- Again, if a result exists, the SP returns the correct row, but also
-- the result of the 1st query is returned without rows...
IF @@ROWCOUNT = 0
BEGIN
SELECT .... WHERE something else again...
END
END
是否有任何选项只返回返回非空行的 SELECT 语句?我不想返回空行......每次该行是第一个查询的“子级别”时,我都会在正确的行之前得到空结果。
我正在考虑创建一个表变量。有没有更好的方法?