IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Comparing a float value to a charecter in DB2


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
ravindra.vadali

New User


Joined: 30 Jan 2012
Posts: 34
Location: USA

PostPosted: Mon Sep 15, 2014 8:28 pm
Reply with quote

Hi All,

GM!!

I have a float value 0.913833 and I need to compare that value to a char value in a table

Exmaple:
Table1:
Code Description
01 0.81
02 0.91
03 0.92

I need to retrieve row 2

so I need to write down a query to check the float value of 0.913833 to a char of 0.91


I did write the following query but it doesnt seem to be working:
SELECT CODE
FROM <Sample table>WHERE
CAST(DESCRIPTION AS FLOAT) = <float value> /* value is 0.913833*/
WITH UR;

Please let me know if you need any further details to help you answer my request.

Any suggestions or comments is greatly appreciated.
Back to top
View user's profile Send private message
ravindra.vadali

New User


Joined: 30 Jan 2012
Posts: 34
Location: USA

PostPosted: Mon Sep 15, 2014 9:03 pm
Reply with quote

Hi All,

I think i have got the desired result using the cast and SUBSTR function

Thanks again.

select code
FROM <Sample table>
WHERE CAST(DESCRIPTION AS FLOAT) = (CAST(SUBSTR(CAST(:<input float value> AS CHAR(9)),1,4) AS FLOAT)

Regards,
Ravi.
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3053
Location: NYC,USA

PostPosted: Mon Sep 15, 2014 10:04 pm
Reply with quote

Always check for performance.

What will happen if you do it in this way? (Hope DESCRIPTION is Char(4))

step 1
Code:
select char(substr(cast ((:<input float value> as varchar(9)),1,4))
into : ws-formated-desc
from sysibm.sysdummy1


step 2

Code:
select code
FROM <Sample table>
WHERE DESCRIPTION =: ws-formated-desc


try and let us know.
Back to top
View user's profile Send private message
ravindra.vadali

New User


Joined: 30 Jan 2012
Posts: 34
Location: USA

PostPosted: Mon Sep 15, 2014 10:48 pm
Reply with quote

Thanks Rohit for your suggestion,
Your query helps too!!

Regards,
Ravi.
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3053
Location: NYC,USA

PostPosted: Tue Sep 16, 2014 1:38 am
Reply with quote

Welcome!!
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Tue Sep 16, 2014 1:48 am
Reply with quote

Convert the FLOAT field to READABLE HEX and that may do the trick.

Search the forums for HEX2CHAR.

HTH....
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Comparing Header and Trailer. DFSORT/ICETOOL 7
No new posts Comparing Signed Packed decimal and p... SYNCSORT 2
No new posts Comparing Comp-3 fields with greater ... DFSORT/ICETOOL 11
No new posts Comparing inside same file DFSORT/ICETOOL 2
No new posts Comparing two sequential files COBOL Programming 14
Search our Forums:

Back to Top