Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Comparing a float value to a charecter in DB2

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
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    Post subject: Comparing a float value to a charecter in DB2
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    Post subject:
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

Senior Member


Joined: 21 Sep 2010
Posts: 1609
Location: NY,USA

PostPosted: Mon Sep 15, 2014 10:04 pm    Post subject:
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    Post subject:
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

Senior Member


Joined: 21 Sep 2010
Posts: 1609
Location: NY,USA

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

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

CICS Moderator


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

PostPosted: Tue Sep 16, 2014 1:48 am    Post subject: Reply to: Comparing a float value to a charecter in DB2
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    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Comparing Decimal and CHAR columns rakesh17684 DB2 7 Thu Oct 20, 2016 2:33 am
No new posts DB2 FLOAT precision soundarr DB2 4 Fri Jul 15, 2016 9:47 pm
No new posts comparing comp-3 and unpacked numbers juares castro COBOL Programming 3 Mon May 30, 2016 6:46 pm
This topic is locked: you cannot edit posts or make replies. JCL to convert float decimal into rea... polymathtarun JCL & VSAM 3 Sun May 15, 2016 9:57 pm
No new posts Need help on comparing hexadecimal va... ashok_uddaraju DFSORT/ICETOOL 4 Thu Apr 28, 2016 2:08 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us