我只設置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語句返回一個非空行?我不想返回空行...並且每次行是第一個查詢的「子級別」時,我會在正確的行之前得到空結果。
我在想創建一個表變量。有沒有更好的方法?
你最終只返回一行嗎?或者有可能這些查詢中有一些會返回多行?形狀是否相同(例如,每列中的相同列數和兼容數據類型)? –