bbesase
bbesase

Reputation: 861

Adding a cast to a parameter

If I have a sql query is it possible for me to add a cast to a dynamic parameter? Here is my sql query:

"SELECT DISTINCT MATERIAL.MATERIALID FROM DATA WHERE MATERIAL.MATERIALID = :VALUE "

I need to cast :VALUE as a double and was just wondering if it's possible

Upvotes: 0

Views: 83

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1270773

You can do this in SQL:

SELECT DISTINCT MATERIAL.MATERIALID
FROM DATA
WHERE MATERIAL.MATERIALID = cast(:VALUE as float)

However, it is a really, really, really bad idea to do equality comparisons on floating point representations of numbers. Two numbers might look the same, but compare differently. Are you sure you can't do the comparison as an integer?

Upvotes: 1

Related Questions