Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Readable "always false" evaluation in TSQL

In my SQL server query I want to always get 0 results. I only want to get the metadata.

How to write an always false evaluation in TSql? Is there a built-in function, or a recommended way of doing so?

Currently I use WHERE 1 = 0, but I'm looking for something like WHERE 'false'.

like image 287
slartidan Avatar asked Oct 19 '22 12:10

slartidan


1 Answers

Although you can use where 1 = 0 for this purpose, I think top 0 is more common:

select top 0 . . . 
. . .

This also prevents an "accident" in the where clause. If you change this:

where condition x or condition y

to:

where 1 = 0 and condition x or condition y

The parentheses are wrong.

like image 138
Gordon Linoff Avatar answered Oct 21 '22 04:10

Gordon Linoff