 select  sale_order,line_no,item_code,due_date, demand, 0 supply, 0 stock_qty, 0 oth_supply, 0 as pending_po, 0 as pending_do, 0 as pending_indent, 0 as pending_dr from 
 (
    SELECT  sorditem.sale_order,sorditem.line_no,item.item_code__plan  as item_code,sorditem.due_date as due_date, 
          ((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, 0 as pending_po, 0 as pending_do, 0 as pending_indent, 0 as pending_dr  
     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('@fromdate@')) 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@ )
 )