SQL Server How to select from expression?

tct7dpnv  于 2023-06-21  发布在  其他
关注(0)|答案(1)|浏览(102)

In PostgreSQL I can issue next query:

=> select 6 between 5 and 7;
 ?column? 
----------
 t
(1 row)

But if I run similar expression in Microsoft SQL server I get the error:

> select 6 between 5 and 7;
Server message number=156 severity=15 state=1 line=8 server=WIN-P5BDUH0CU0N text=Incorrect syntax near the keyword 'between'

How to select from expression in Microsoft SQL server?

4xrmg8kj

4xrmg8kj1#

Thank you to @ThomA and @Charlieface. Next expression works fine for me:

select IIF( 8 between 5 and 7, 1, 0 );

@Horaciux query is what I was looking for:

SELECT CASE WHEN 6 BETWEEN 5 AND 7 THEN 't' ELSE 'f' END AS Result;

相关问题