sql server 2008 - Stored procedure return SELECT only with rows -


i set sql stored procedure return specific row in specific order (from more less important):

-- 1st level -> query more detailed object... select ... -- if result find, sp returning correct row. -- if rowcount = 0 then, sp returning empty row  -- , continues next query (less specific 1st one).  if @@rowcount = 0 begin select .... else...   -- again, if result exists, sp returns correct row,   -- result of 1st query returned without rows...  if @@rowcount = 0  begin  select .... else again...  end end 

is there option return select statement returns non empty row? don't want return empty rows... , each time row "sub-level" of 1st query, empty results before correct row.

i thinking create table variable. there better ways?

since looking lack of rows why not use if/else statement in procedure. like:

if exists(/*firstquery*/ select ... something) begin    select ... end else if exists (/*secondquery*/ select .... else... ) begin    select .... else...  end else /*third query*/ begin     select .... else again... end 

just remember when checking exists should select 1 column (for example id) if have calculated columns can slow down procedure.


Comments

Popular posts from this blog

How do you change vbulletin's home page to the forums instead of the default (CMS or Activity Stream)? -

c++ - Troubles when compiling phash program -