If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > SQL case statement query

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-03-09, 17:30
maanas maanas is offline
Registered User
 
Join Date: Jan 2009
Posts: 4
SQL case statement query

Hi.

I have been facing an issue for a few days of messages mismatches.

We set the Match status using the following query

set
MTCH_STA = CASE ((coalesce (CR_AMT,0) +
:h_CR_AMT) - (coalesce(DB_AMT,0) + :h_DB_AMT))
WHEN 0 THEN 2 /* matched */
ELSE 1
END,


It seems that DB2 does not treat 0.00 as 0 some of the times as around 1/3rd of the messages remain unmatched even when the CR_AMT , DB_AMT are equal.

any ideas about this?
Reply With Quote
  #2 (permalink)  
Old 02-03-09, 17:43
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
What is the data type of the values you claim to be 0.00? If it is a floating point number, then you know that you cannot rely on for exact comparisons anyway.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #3 (permalink)  
Old 02-03-09, 17:47
Peter.Vanroose Peter.Vanroose is offline
Registered User
 
Join Date: Sep 2004
Location: Belgium
Posts: 1,079
Quote:
Originally Posted by maanas
set
MTCH_STA = CASE ((coalesce (CR_AMT,0) +
:h_CR_AMT) - (coalesce(DB_AMT,0) + :h_DB_AMT))
WHEN 0 THEN 2 /* matched */
ELSE 1
END
Does the following return the same result?
Code:
set 
MTCH_STA = CASE WHEN coalesce(CR_AMT,0) + :h_CR_AMT =
                     coalesce(DB_AMT,0) + :h_DB_AMT
                THEN 2  ELSE 1    END
__________________
--_Peter Vanroose,
__IBM Certified Database Administrator, DB2 9 for z/OS
__IBM Certified Application Developer
__ABIS Training and Consulting
__http://www.abis.be/
Reply With Quote
  #4 (permalink)  
Old 02-03-09, 17:47
maanas maanas is offline
Registered User
 
Join Date: Jan 2009
Posts: 4
the DB column is DECIMAL(15,3)
and the host variable is double.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On