Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Informix Sub Query: Case Statement

Status
Not open for further replies.

greengo204

Technical User
Apr 7, 2009
56
AU
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
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top