Monday, September 21, 2015

Trans-SQL Query - return empty row from Sql Server

Generally, if you must have an empty row returned..
If your original query is:
 select a,b,c from query_table where a='something'

You can turn it into a subquery:

select t.a,t.b,t.c
from (select 1 as adummy) a left join (
    select a,b,c from query_table where a='something'
) t on 1=1

Which ensures the query will always have a rowcount of at least one.