How to handle null columns while using minus

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ramanammurthy
    New Member
    • Sep 2014
    • 1

    How to handle null columns while using minus

    Code:
    select distinct item_code ,item_description ,item_type_name,item_group_name
    from tblitemmaster
    minus
    select distinct item_code ,item_description ,to_char(null) as item_type_name, to_char(null) as item_group_name
    from tblbinlocation  
    where transaction_type in('Indent','MDN')
    and voucher_date 
    between TO_CHAR(TO_DATE('01-03-2014', 'DD-MM-YYYY')) 
    and TO_CHAR(TO_DATE('31-08-2014', 'DD-MM-YYYY'))
    The above query getting wrong output,it will display all records from tblitemmaster table,if it is not use null colums ,minus getting perfect output.

    Insted of the above query am using not exists

    Code:
    select distinct item_code ,item_description,item_type_name,item_group_name
    from tblitemmaster
    where not exists (select distinct item_code from tblbinlocation
    where tblitemmaster.item_code = tblbinlocation.item_code 
    and transaction_type in('Indent','MDN') and 
    voucher_date  
    between TO_CHAR(TO_DATE('01-03-2014', 'DD-MM-YYYY')) 
    and TO_CHAR(TO_DATE('31-08-2014', 'DD-MM-YYYY')))
    But,the above query getting correct output.

    Minus and not exists concepts are same.but,the two queries are getting different output.2nd query only correct output.
    How to alter the 1st query and i want correct result like 2nd query.
    Thanks in advance.
  • mukherjee
    New Member
    • Sep 2014
    • 9

    #2
    You may try to use ISNULL(column, value) method.

    Comment

    Working...