Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IIF IN A VIEW QUESTION

Status
Not open for further replies.

robmoors

Programmer
Jan 10, 2001
24
Can I put a IIF statement in a VIEW like I can in Access query? If I can, can you give me an example, if not what do I use to replace the IIF statement.

Thank you in advance.
 
You cannot use IIF in SQL Server, but you can use the CASE statement.
 
You may use "CASE WHEN ... ".
For example if you have a table
Product( ID , Name , Stock )
where id = primary key

SELECT ID, Name , Stock , Info = CASE
WHEN Stock >= 1000 THEN 'OK'
ELSE 'not ok'
FROM Product (SQL Server version)

is equivalent with

SELECT ID, Name, Stock, IIF( Stock >= 1000 , 'ok' , 'not ok' )
FROM Product

 
SELECT ID, Name, Stock, IIF( Stock >= 1000 , "ok" , "not ok" )
FROM Product
in MS Access
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top