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

SQL

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Is there an if statement in SQL and if so what is its structure.
 
Look into the documentation on the "WHERE" clause. It has the same sort of function. You can do this either in SQL directly with something like ...

WHERE Type>=20 AND Type<=29

Or, you can use the Query builder:
1) choose your table
2) drag the fields you want to the grid
3) set the field's &quot;Criteria&quot; to something like...

>=20 AND <=29

notice that &quot;Type&quot; is assumed in this case by the query builder. Go into SQL view to see the SQL code generated by the builder.

Anyway... you'll see plenty of documentation on it.
 
No. There is no if statement in SQL.
If you want to apply a SQL statement where clause, or select one of two or more SQL statements from a list of several, you would have to write your SQL statement in VBA and use the if statement in VBA.
Does that make sense? I'm doing the same (for the first time) myself.
Let me know if you'd like some sample code.
kempmike65@aol.com
 
There is no If statement, but you can code a valid VBA expression as a value to be retrieved by the SELECT statement, and the expression can include the IIf function:

SELECT IIf([CustType]=&quot;B&quot;,[BusinessName],[PersonalName]) FROM Customers;

Depending on why you need IF logic, that may work for you. Rick Sprague
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top