Using IIF in a View 
Author Message
 Using IIF in a View

Hi

I have 2 tables, TableA and TableB, both with address details.  TableA has a
field that says UseTableBAddress, if this field is equal to 1, then use the
address details of TableB else use the address details of TableA.

In the column of my view I have this statement:
    IIF(TableA.UseTableBAddress=1, TableB.Address, TableA.Address)

When I click on check syntax (SQL Server 7), I get an error saying that IIF
is not a function.  Are you able to do what I have described in a view?  If
so, what am I doing wrong?

Regards

Craig



Tue, 22 Jan 2002 03:00:00 GMT
 Using IIF in a View

Well,

 Think about using CASE -WHEN.

Regards

Adrian Knight



Quote:
> Hi

> I have 2 tables, TableA and TableB, both with address details.  TableA has
a
> field that says UseTableBAddress, if this field is equal to 1, then use
the
> address details of TableB else use the address details of TableA.

> In the column of my view I have this statement:
>     IIF(TableA.UseTableBAddress=1, TableB.Address, TableA.Address)

> When I click on check syntax (SQL Server 7), I get an error saying that
IIF
> is not a function.  Are you able to do what I have described in a view?
If
> so, what am I doing wrong?

> Regards

> Craig



Tue, 22 Jan 2002 03:00:00 GMT
 Using IIF in a View
Craig,

Quote:
> Subject: Using IIF in a View

Q.  What is the equivalent of the IIF command in SQL Server?
(v1.0 1999.05.13)

A.  In MS Access you would use :-

  Select iif(field>10,"large", "small") as Size from Table

With SQL Server, use the CASE command

SELECT Size =
  CASE field
  WHEN field > 10 THEN "large"
  ELSE "small"
from Table

 Neil Pike MVP/MCSE.  Protech Computing Ltd
 (Please reply only to the newsgroup unless indicated otherwise)
 For SQL FAQ entries see
 sqlfaq.zip in http://go.compuserve.com/sqlserver.  Download from lib 1.
 or www.ntfaq.com/sql.html (download as part of ntfaq)
 or http://www.swynk.com/faq/sql/sqls



Tue, 22 Jan 2002 03:00:00 GMT
 
 [ 3 post ] 

 Relevant Pages 

1. iif function in views

2. IIF function inside a view

3. iif functions in views / procedures

4. IIF function in view ???

5. equivalent for IIF (in VIEWS)

6. decode or iif in SQL 7 view?

7. How to se IIF or Case statements in a view to create a column

8. Can I use IIF in SQL views?

9. How to use IIF function in a view

10. equivalent for IIF (in VIEWS)

11. IIF or CASE type function in SQL views

12. IIF FUNCTION IN A VIEW


 
Powered by phpBB® Forum Software