简体   繁体   English

等效于Case SQL语句中的IFF

[英]Equivalent of IFF in Case SQL statement

I am trying to convert an access IFF query to an SQL Server query 我正在尝试将访问IFF查询转换为SQL Server查询

SELECT blah blah ,
    IIf([stock]![supplier]=[pos]![supplier],"Preferred"," ") AS Preferrednew 
FROM blah blah

In access this will give a value of preferred in a column called Preferrednew where the condition is true. 在访问中,这将在条件为true的称为Preferrednew的列中提供preferred的值。

I have converted the code to.. 我已将代码转换为

SELECT blah blah ,
 CASE WHEN ([stock.supplier] = [pos.supplier]), 'test', 'test2' AS [preferrednew]
FROM blah blah

but I get the error 但是我得到了错误

Incorrect syntax near ',' ','附近的语法不正确

What is the correct format ? 正确的格式是什么?

SELECT blah blah ,
    CASE WHEN stock.supplier = pos.supplier THEN 'test'
    ELSE 'test2'
    END AS [preferrednew]
FROM blah blah

Keep in mind that SQL Server 2012+ supports IIF 请记住,SQL Server 2012+支持IIF

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM