×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Informix Sub Query: Case Statement

Informix Sub Query: Case Statement

Informix Sub Query: Case Statement

(OP)
Informix DB

i was wondering if someone could help me writing a sub query using just a case statement (if possible) so far i got:

CODE

(
SELECT
    CASE
    WHEN IS NULL (sum (po_order_line.order_line_amnt))
        THEN 'ZERO'
    WHEN sum (po_order_line.order_line_amnt) > 0 AND sum (po_order_line.order_line_amnt) < 1000
        THEN 'LOW'
    WHEN sum (po_order_line.order_line_amnt) >= 1000 AND sum (po_order_line.order_line_amnt) < 2000
        THEN 'MEDIUM'
    WHEN sum (po_order_line.order_line_amnt) >= 2000
        THEN 'LARGE'
    ELSE
        sum (po_order_line.order_line_amnt)    
    END,
FROM
    popes:popesdba.po_order po_order,
    popes:popesdba.po_order_line po_order_line,
    popes:popesdba.po_invc po_invc
WHERE
    po_fi_cnrct.cnrct_id = po_order.fi_cnrct_id AND
    po_order.order_id = po_order_line.order_id AND
    po_order.order_stat_cd = po_order_line.order_stat_cd AND
    po_order.invc_id = po_invc.invc_id
)

I was wondering if its possible to have just a case statement in a subquery and if anyone could suggest where i have gone wrong in the above code.

Im very new at writing SQL so please be gentle...

Cheers
 

RE: Informix Sub Query: Case Statement

1) You cannot test a number for being NULL.

2) The comma after the END (CASE) statement should not be there unless you intend to show more columns?  

You should try the following:

SELECT
    CASE
    WHEN sum(po_order_line.order_line_amnt) = 0
        THEN 'ZERO'
    WHEN sum(po_order_line.order_line_amnt) > 0 AND sum(po_order_line.order_line_amnt) < 1000
        THEN 'LOW'
    WHEN sum(po_order_line.order_line_amnt) >= 1000 AND sum(po_order_line.order_line_amnt) < 2000
        THEN 'MEDIUM'
    WHEN sum(po_order_line.order_line_amnt) >= 2000
        THEN 'LARGE'
    ELSE
        sum (po_order_line.order_line_amnt)    
    END CASE
FROM  .........etc....

Hope this helps
Dave

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close