Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2004
    Posts
    51

    Question Unanswered: 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.

  2. #2
    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

  3. #3
    Join Date
    Mar 2004
    Posts
    51

    Talking

    Thanks! It works great!

  4. #4
    Join Date
    Mar 2004
    Location
    Toronto, ON, Canada
    Posts
    513
    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

  5. #5
    Join Date
    Mar 2004
    Posts
    51
    Cool, thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •