Is it possible to return empty row from Sql Server? Is it possible to return empty row from Sql Server? sql-server sql-server

Is it possible to 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 tbl

You can turn it into a subquery

select t.a,t.b,t.cfrom (select 1 as adummy) aleft join (    select a,b,c from tbl  -- original query) t on 1=1

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


If your objective is to return a query with no records, or with an empty recordset/dataset, the following should work without any previous knowledge on the original query:

SELECT * FROM (myOriginalQuery) as mySelect WHERE 0 = 1


Based on Richard's answer, you can use UNIONS to give you "something"...

select t.a, t.b, t.cfrom (select null AS a, null AS b, null AS c       union ALL      select a, b, c from tbl)   -- original query     ) AS t on 1=1

The '1=1' is really what forces SQL to return something.