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 > IF statements in the query

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-14-04, 10:56
nbozic nbozic is offline
Registered User
 
Join Date: Mar 2004
Posts: 51
Question IF statements in the query

Hi,

I was wondering if anyone can give me a hint with this problem.

The query:

SELECT ID_Number, WeightValue, WeightCode, |||| WeightLB, WeightKG ||||
from tbl_weight

Fields WeightLB and WeightKG don't really exist in the table and would be generated dynamically in the query.

Here is an example of what exactly I need to do:
I read the first record from table tbl_weight.
The values are as follows:
ID_Number: ABC, WeightValue: 70, WeightCode: KG
The WeightValue is 70KG, but I also want to know how many pounds (LBs) this is...
Because of that I automatically select 70 for the WeightKG, but calculate WeightLB dynamically by multiplying 70 by 2.2.
The final result:
ID_Number: ABC, WeightValue: 70, WeightCode: KG, WeightLB: 154, WeightKG: 70
In that case I would have all the info I need...
Similar thing happens when I get LB and need to dynamically calculate KG, except I'll multiply by 0.45.

I assume I would need to use some kind of IF statements in the query. Any ideas?

Thanks.
Reply With Quote
  #2 (permalink)  
Old 04-14-04, 12:30
J Petruk J Petruk is offline
Registered User
 
Join Date: Mar 2004
Location: Toronto, ON, Canada
Posts: 513
CASE
WHEN WeightValue = 'KG' THEN ...
ELSE
END as converted_weight
__________________
--
Jonathan Petruk
DB2 Database Consultant
Reply With Quote
  #3 (permalink)  
Old 04-14-04, 12:37
nbozic nbozic is offline
Registered User
 
Join Date: Mar 2004
Posts: 51
Talking

Thanks! It works great!
Reply With Quote
  #4 (permalink)  
Old 04-14-04, 12:46
J Petruk J Petruk is offline
Registered User
 
Join Date: Mar 2004
Location: Toronto, ON, Canada
Posts: 513
Quote:
Originally posted by nbozic
Thanks! It works great!
No problem.

If you download one thing today, make it this:
http://ourworld.compuserve.com/homep...l/HTM_COOK.HTM

It has everything you wanted to ever do with SQL in DB2. Incredibly valueable resource, and unbelievably it's FREE.
__________________
--
Jonathan Petruk
DB2 Database Consultant
Reply With Quote
  #5 (permalink)  
Old 04-14-04, 13:46
nbozic nbozic is offline
Registered User
 
Join Date: Mar 2004
Posts: 51
Cool, thanks!
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