ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

SQL subselect

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • SQL subselect

    I have the following SQL statement... the two subselect statements can return NULL values. Because I use the subselect results in a calculation, I need for the result to be 0 instead of NULL.

    How do I do that?

    Code:
    -- Calculate Kit Available Qty based on component with lowest qty available
    select ifcom#, ifprt#, ifprt2, ifqty#, ieqoh#, (ieqoh# -
    (select sum(odctt#) from oeordlod where odcom#=ifcom# and odprt#=ifprt2 and odwhs#='MLP') -
    (select sum(odalc#) from oeordlod where odcom#=ifcom# and odprt#=ifprt2 and odwhs#='MLP') -
    ieqrs#)/ifqty# as avail
    from oebilmif
    join icbalmie on iecom#=ifcom# and ieprt# = ifprt2 and iewhs#='MLP'
    where ifcom#='027' and ifprt#='01024771519'
    order by avail asc
    fetch first row only;

  • #2
    Figured it out... can't delete the post.

    COALESCE(sum,0)

    Comment

    Working...
    X