SQL查询:
SELECT *
FROM Account
WHERE (type <>100000002 ? Id='something': Id=null)
但它显示错误:
'?'
附近的语法不正确
请帮帮我。
答案 0 :(得分:10)
这适用于SQL Server。 IIF
在SQL Server 2008或更早版本中不可用。
SELECT *
FROM Account
WHERE
Id=IIF(type<> 100000002,"something",null )
如果您使用的是SQL Server 2008或更早版本,请尝试此操作。
SELECT *
FROM Account
WHERE (Id= CASE WHEN type <>100000002 THEN 'something' ELSE null END)
答案 1 :(得分:5)
你可以这样做:
SELECT *
FROM Account
where (type <>100000002 and Id='something') or (type =100000002 and id is null)
或
SELECT *
FROM Account
where isnull(id,'_null_')= case when type <>100000002 then 'something' else isnull(id,'_null_') end
答案 2 :(得分:2)
SELECT *
FROM Account
WHERE (Id= CASE WHEN type <>100000002 THEN 'something' ELSE null END)
答案 3 :(得分:1)
使用以下内容:
SELECT *
FROM Account
WHERE (Id= CASE WHEN type != 100000002 THEN 'something' ELSE null END)
或
SELECT *
FROM Account
WHERE (Id= CASE WHEN type <> 100000002 THEN 'something' ELSE null END)
答案 4 :(得分:1)
SELECT *
FROM Account
where (type <>100000002 and Id='something') or (type =100000002)
答案 5 :(得分:0)
你可以使用case ...然后在sql中看到这个链接 http://blog.sqlauthority.com/2007/04/14/sql-server-case-statementexpression-examples-and-explanation/