Use IIF inside a query,....

Use IIF inside a query,....

Post by Andrew Oftheson » Fri, 13 Jun 2003 22:14:32



Hi, I have this simple query:

SELECT     COUNT(id) AS Number, seleccion & 4096 AS HasByte13
FROM         usuario2
GROUP BY seleccion & 4096

I will get a result like:
number HasByte13
1234    4096
9988         0

But i want something like:
number HasByte13
1234    yes
9988    no

So in access i would do:
SELECT     COUNT(id) AS Number, iif(seleccion & 4096=0;"No"; "Yes") AS
HasByte13
FROM         usuario2
GROUP BY seleccion & 4096

but this is an error in SQL server.....

any ideas?

 
 
 

Use IIF inside a query,....

Post by Aaron Bertrand - MV » Fri, 13 Jun 2003 22:23:56


Quote:> So in access i would do:
> SELECT     COUNT(id) AS Number, iif(seleccion & 4096=0;"No"; "Yes") AS
> HasByte13
> FROM         usuario2
> GROUP BY seleccion & 4096

Try:

SELECT
    HasByte13 = CASE WHEN seleccion & 4096=0 THEN 'No' ELSE 'Yes' END,
    ...othercolumns...
    FROM ...

A

 
 
 

Use IIF inside a query,....

Post by Ned Radenovi » Fri, 13 Jun 2003 22:37:35


If you looking for the equivalent of the IIF statement,
lookup the CASE statement in SQL Books online.

regard,

Ned

Quote:>-----Original Message-----
>Hi, I have this simple query:

>SELECT     COUNT(id) AS Number, seleccion & 4096 AS
HasByte13
>FROM         usuario2
>GROUP BY seleccion & 4096

>I will get a result like:
>number HasByte13
>1234    4096
>9988         0

>But i want something like:
>number HasByte13
>1234    yes
>9988    no

>So in access i would do:
>SELECT     COUNT(id) AS Number, iif(seleccion &

4096=0;"No"; "Yes") AS

- Show quoted text -

Quote:>HasByte13
>FROM         usuario2
>GROUP BY seleccion & 4096

>but this is an error in SQL server.....

>any ideas?

>.

 
 
 

1. Using IIF Function in Sql Server 2000 Query ?

The following query generates syntax error.

select customerid,
IIF(CUSTOMERID="ALFKI","ALFKI","LUQ") FROM CUSTOMERS

I need if customerid='ALFKI', then query to return 'ALFKI' ELSE IT SHOULD
RETURN 'LUQ'

What am I missing ?

Best Regards,

Luqman

2. Data Environment

3. ADO using Access database queries with IIF problem

4. pgsql/src/include/utils timestamp.h

5. IIF function in sql statement equal to what is used in Access-Query

6. Designing GL for flexibility

7. IIF function inside a view

8. Portal? HELP!

9. upgrading IIF-9.21-UC2 to IIF-9.21-UC3 and select became

10. Using IIF - SQL Server and Access

11. PFW: query -- OR, iif?

12. IIF expression used in GROUP BY

13. IIF function in query