Is it possible to force Sql Server to return empty fields instead of nothing when such fields do not exist?

Think about this table:

 ____________
| ID | Value |
|  1 |  One  |
|  3 | Three |

If I run a query like this SELECT Value FROM myTable WHERE ID = 1, I will definitely get its suitable value, be it Onein this case, but if I change IDto any other number that does not exist in this table, Of course, I will not get anything in the column Value, since there there would be no data.

But is there a way to force Sql Server to return at least empty space when performing such queries?

Sql Fiddle with the same case: http://sqlfiddle.com/#!3/f30f8/2

0
source share
2 answers
select  Value
from    YourTable
where   ID = 1
union all
select  null
where   not exists
        (
        select  *
        from    YourTable
        where   ID = 1
        )

, , , .

+2

. :

select coalesce(max(value), '')
from test t
where id = 1;

, max() . NULL, , ( - ).

+1

All Articles