LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default SQL embedded "IF" statement

dave k wrote:
Is there a way to embed an if statement into a SQL select?

SELECT F1, F2, IF(F11,F1*3,F1*2) FROM ATABLE


Your use of F1 suggests you are querying Excel using MS Jet. Jet does
not support the standard SQL CASE WHEN syntax, so try IIf (immediate
if) e.g.

SELECT F1, F2, IIF(F11,F1*3,F1*2) FROM ATABLE;

For more complex case statements, you could use SWITCH e.g.

SELECT F1, F2, SWITCH(
F11 AND F1<=2, F1*3,
F12 AND F1<=3, F1*4,
1=1, F1*2
) FROM ATABLE;

Jamie.

--



 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
embedding "ISERROR" function into an "IF" statement [email protected] Excel Worksheet Functions 8 January 4th 07 12:01 AM
vba: How do I write a "For Each Statement" nested in a "With Statement"? Mcasteel[_30_] Excel Programming 1 November 8th 04 09:47 PM
vba: How do I write a "For Each Statement" nested in a "With Statement"? Mcasteel[_27_] Excel Programming 1 November 8th 04 09:23 PM
vba: How do I write a "For Each Statement" nested in a "With Statement"? Mcasteel[_29_] Excel Programming 0 November 8th 04 09:08 PM


All times are GMT +1. The time now is 11:12 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"