If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Support of iif statement?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-27-03, 11:22
AS400Admin AS400Admin is offline
Registered User
 
Join Date: Aug 2003
Posts: 39
Support of iif statement?

We are using DB2400 for AS400 and are trying to convert some of our reports from MS Access to directly to DB2.

We have been using Access as a go between for some reports because we use the "iif" function/statement but we would like to get away from that.

Does anyone know of a why to pass an "iif" or something simiar to DB2400?

TIA

Ryan
Reply With Quote
  #2 (permalink)  
Old 10-27-03, 13:11
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
select IIF(foo='bar',qux,937) as zorp

becomes

select CASE when foo='bar' then qux else 937 END as zorp
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 10-29-03, 09:57
AS400Admin AS400Admin is offline
Registered User
 
Join Date: Aug 2003
Posts: 39
Quote:
Originally posted by r937
select IIF(foo='bar',qux,937) as zorp

becomes

select CASE when foo='bar' then qux else 937 END as zorp
Thanks for the help! Unfortunately, we haven't been able to use the case statement in a WHERE clause, only SELECT (as your example depicted).

Currently, MS Access supports IIF in the WHERE clause so we have our reporting software connecting to the AS400 through linked tables in MS Access. We are trying to get away from that.

Let me know if a look at the SQL would help.

Thanks in advance.

Ryan
Reply With Quote
  #4 (permalink)  
Old 10-29-03, 12:24
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
yes, let's have a look at your query

according to the DB2 Universal Database for iSeries SQL Reference manual Case expressions section, you should be able to do it

the example given in that section is
Code:
SELECT EMPNO, WORKDEPT, SALARY+COMM
  FROM EMPLOYEE
  WHERE (CASE WHEN SALARY=0 THEN NULL
              ELSE COMM/SALARY
         END) > 0.25
rudy
Reply With Quote
  #5 (permalink)  
Old 10-31-03, 11:00
AS400Admin AS400Admin is offline
Registered User
 
Join Date: Aug 2003
Posts: 39
Rudy, your are right. We just tried it (and I book marked that reference site). Maybe it didn't work prior to V5R2. We originally wrote the reports in V4R5 and we really thought it wouldn't work.

Thanks for your help.

Ryan
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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