Sql 2005 alternate query access
Hi I am stuck with the following query I wrote for Access and it works correctly. But when I run it through SQL 2005 it gives me an error ( Invalid syntax next to "IS" keyword ).
I went through similar questions but there was no solution to my problem.
Here is an Access query.
select iif(ISBN IS Null,"1","0") as OK from products
Please use SQL 2005 version.
It may be a basic query, but I am new to sql.
Thanks in advance.
source to share
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 .
UPDATE
SELECT CASE
WHEN expression1
THEN 0
ELSE
CASE
WHEN expression2
THEN 2
ELSE 3
END
END AS OK
FROM products
source to share
You will need a CASE
replacement expression IIf()
. SQL Server 2005 has no feature IIf()
:
select case when ISBN is null then 1 else 0 end as OK
from products
If you have additional instructions IIf()
, you can attach them:
select
case
when ISBN is null
then 1
else
case when yourCol = "Value"
then 2
else 3
end
end as OK
from products
source to share