Kasper Hansen
Kasper Hansen

Reputation: 6557

An 'IN' inside an 'IFF' gives a syntax error

I cannot figure out why this is wrong. The syntax for an IFF is defined here:

https://msdn.microsoft.com/en-us/library/hh213574.aspx

enter image description here

Why does it complain about the IN operator?

Upvotes: 2

Views: 48

Answers (1)

Christian Barron
Christian Barron

Reputation: 2755

It looks like you're using a version of SQL Server that does not support this function (pre SQL Server 2012). An alternative is to use a case statement like so:

Select NEWID(), m.MALEPUNKTYPE, 
       case when m.MALEPUNKTYPE in ('E17', 'E18') then 'D02' else null end
from AMALD m

This is supported from SQL Server 2005 onwards however it should work on earlier versions too

Upvotes: 1

Related Questions