View previous topic :: View next topic
|
Author |
Message |
ravindra.vadali
New User
Joined: 30 Jan 2012 Posts: 34 Location: USA
|
|
|
|
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 |
|
|
ravindra.vadali
New User
Joined: 30 Jan 2012 Posts: 34 Location: USA
|
|
|
|
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 |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3053 Location: NYC,USA
|
|
|
|
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 |
|
|
ravindra.vadali
New User
Joined: 30 Jan 2012 Posts: 34 Location: USA
|
|
|
|
Thanks Rohit for your suggestion,
Your query helps too!!
Regards,
Ravi. |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3053 Location: NYC,USA
|
|
|
|
Welcome!! |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
Convert the FLOAT field to READABLE HEX and that may do the trick.
Search the forums for HEX2CHAR.
HTH.... |
|
Back to top |
|
|
|