 select  item_code,due_date, round((demand),0) demand, (supply) supply, (stock_qty) stock_qty, (oth_supply) oth_supply,sale_order, line_no from 
 (
   SELECT  item.item_code__plan  as item_code,sorditem.due_date as due_date, sorditem.sale_order, sorditem.line_no,
          ((case when sorditem.quantity is null then 0 else sorditem.quantity end - case when sorditem.qty_alloc is null then 0 else sorditem.qty_alloc end - case when sorditem.qty_desp is null then 0 else sorditem.qty_desp end )  * case when sorditem.conv__qty_stdqty is null then 1 else sorditem.conv__qty_stdqty end ) as demand, 
          0 as supply, 0 as stock_qty, 0 as oth_supply  
     FROM sorder,sorditem, item 
      WHERE ( sorditem.item_code = item.item_code ) and 
            (sorder.sale_order = sorditem.sale_order ) and 
            (case when sorder.confirmed is null then 'N' else sorder.confirmed end         = 'Y' ) and 
            (case when sorditem.consume_fc is null then 'Y' else sorditem.consume_fc end = 'N' ) and 
            (sorditem.site_code in ('@sitecode@') ) AND 
          ( item.item_code__plan = '@itemcode@') AND 
            (sorditem.due_date <= to_date('@todate@')) and 
            ( case when sorder.status is null then 'P' else sorder.status end = 'P') and 
            ( sorder.order_type not in (@ordtypes@) ) and 
            ( 0 = @madetoorder@ ) 
 
 )  
 where (demand) <> 0 or (supply) <> 0