Hi I am stuck in the following query which I have written for Access and working properly. But when I am running it through SQL 2005, it gives me error (Incorrect syntax near the keyword 'IS').
你好,我被困在下面的查询中,这是我为访问和正常工作而编写的。但是当我通过SQL 2005运行它时,它会给我错误(在关键字“IS”附近的语法错误)。
I have been through similar questions but there was no solution to my problem.
我也遇到过类似的问题,但是我的问题没有解决的办法。
Here is the Access query.
这是访问查询。
select iif(ISBN IS Null,"1","0") as OK from products
Please need a SQL 2005 version.
请需要一个SQL 2005版本。
This might be a basic query but i am new to sql.
这可能是一个基本的查询,但我是sql新手。
Thanks in advance.
提前谢谢。
2 个解决方案
#1
4
use CASE
instead.
用例。
SELECT CASE
WHEN ISBN IS Null
THEN 1
ELSE 0
END AS OK
FROM products
but IIF
should work if you are using SQL Server 2012.
但是如果您正在使用SQL Server 2012, IIF应该可以工作。
UPDATE
更新
SELECT CASE
WHEN expression1
THEN 0
ELSE
CASE
WHEN expression2
THEN 2
ELSE 3
END
END AS OK
FROM products
#2
1
You will need to you a CASE
expression to replace the IIf()
. SQL Server 2005 does not have an IIF()
function:
您将需要一个CASE表达式来替换IIf()。SQL Server 2005没有IIF()函数:
select case when ISBN is null then 1 else 0 end as OK
from products
If you have additional IIF()
statements then you can nest them:
如果您有其他的IIF()语句,那么您可以嵌套它们:
select
case
when ISBN is null
then 1
else
case when yourCol = "Value"
then 2
else 3
end
end as OK
from products
#1
4
use CASE
instead.
用例。
SELECT CASE
WHEN ISBN IS Null
THEN 1
ELSE 0
END AS OK
FROM products
but IIF
should work if you are using SQL Server 2012.
但是如果您正在使用SQL Server 2012, IIF应该可以工作。
UPDATE
更新
SELECT CASE
WHEN expression1
THEN 0
ELSE
CASE
WHEN expression2
THEN 2
ELSE 3
END
END AS OK
FROM products
#2
1
You will need to you a CASE
expression to replace the IIf()
. SQL Server 2005 does not have an IIF()
function:
您将需要一个CASE表达式来替换IIf()。SQL Server 2005没有IIF()函数:
select case when ISBN is null then 1 else 0 end as OK
from products
If you have additional IIF()
statements then you can nest them:
如果您有其他的IIF()语句,那么您可以嵌套它们:
select
case
when ISBN is null
then 1
else
case when yourCol = "Value"
then 2
else 3
end
end as OK
from products