Is it possible to return an empty string from Sql Server?

Is it possible to return all columns in a query as an empty column (not empty) or an empty row if the actual query does not return rows

+6
source share
3 answers

Generally, if you should return an empty string.

If your original request

select a,b,c from tbl 

You can include it in a subquery

 select ta,tb,tc from (select 1 as adummy) a left join ( select a,b,c from tbl -- original query ) t on 1=1 

which ensures that the query will always have a row number of at least one.

+12
source

If your goal is to return a query without records or with an empty recordset / dataset, the following should work without any prior knowledge of the original query:

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

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

 select ta, tb, tc from (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 

' 1=1 ' is what causes SQL to return something.

0
source

Source: https://habr.com/ru/post/1343617/


All Articles