Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server functional equivalent to PostgreSQL "in"

In postgres you can do a comparison against multiple items like so:

 SELECT 'test' IN ('not','in','here');

Which is the same as doing:

  SELECT ('test' = 'not' OR 'test' = 'in' OR 'test' = 'here');

Is there a functional equivalent for SQL Server ?

like image 285
Tyler Avatar asked Mar 27 '26 01:03

Tyler


1 Answers

It is supported, but you will need to put the expression somewhere that accepts a boolean expression. For example, in a case statement:

select  case  when 'test' in ('not','in','here')  then 1  else 0  end

----------- 
0

(1 row(s) affected)

Or a where clause:

select * from T where C in (1,3,5,7,9)
like image 130
xahtep Avatar answered Mar 29 '26 23:03

xahtep