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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using an IIF or IF in an SQL view 1

Status
Not open for further replies.

smuthcrmnl777

Technical User
Jan 16, 2006
104
US
In SQL, I would like to create a view that I have a simple IF or IIF command in the field name. I know how to create If statements in SQL and I know how to create IIF statements in MS ACCESS, but I need to have a field name test a criteria and then displaying the correct data when the view executes.

Ex:

Ms ACCESS allows you to put this in the field name.

=IIF(['Auto']="Lexus",1,0,)

 
In a view, the best way is to do a case when statement.

Select field1, field2, Case When Auto = 'Lexus' Then 1.0 Else Auto End As Auto
From. . . .

You can repeat the case when repeatedly for as many options as you like. Just don't forget the "End"!
Hope that helps.
 
BTW - there are two forums where these questions might be more appropriate - there is one on SQL Server Programming, and there is one on Access Projects. It's more likely someone who knows the answer to this kind of thing will be on those forums.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top