Reputation: 2691
Edited:
I have a search stored procedure. The stored procedure receives a few bit parameters named @filter1, @filter2, etc. The parameters indicates if a contextual filter will be returned or not by the procedure. Yet, the procedure can return errors. Something like:
if error
select * from erros
else
select 0
if filter1
select * from tablea
else
select 1
select * from search
The select 0
and select 1
statements are there just to keep the search at the same position, but they cause a little of spaghetti code in the back end, because I have to check the table content to figure out if there's a error or not and evaluate several filter parameters in order to build my objects properly. It's simpler to check how many rows are inside the table.
My question is, is there a non expensive way to return a empty dataset to avoid the select 0 and select 1 statements?
Upvotes: 0
Views: 1963
Reputation: 12672
Try this
select top 0 * from tablea
select top 0 * from tableb
That will return empty rows with the columns of TableA
and TableB
Upvotes: 1