Casting a number literally changes it....

Hi,

I am using an ODBC Connection to ServiceNow and write code using SqlDbx which uses a form on mySql.

Lately I have been having issues when trying to cast or convert a number.

A simple count(*) may return say 1819 records, yet if i try to cast this like so CAST(COUNT(*) AS float) i get 5,457 records.

How can it be doing this!!??

April 21st, 2015 12:32am

Thanks for publish your question here. But, this is SQL Server forum. For SqlDbx, please visit this URL: http://www.sqldbx.com/support.htm.
Free Windows Admin Tool Kit Click here and download it now
April 21st, 2015 12:39am

The result does seem odd - but if you want an exact result you shouldn't be casting to float.  Float is an approximate data type.  To quote books online "Floating point data is approximate; therefore, not all values in the data type range can be represented exactly."

Is there a specific reason you are casting to float? 

https://msdn.microsoft.com/en-AU/library/ms173773.aspx?f=255&MSPPError=-2147217396

April 21st, 2015 12:42am

Nope I dont feel thats not correct

I dont think the value will change as above just because of casting

I feel its undergoing some other operation / conversion which is causing it to change value like this

Free Windows Admin Tool Kit Click here and download it now
April 21st, 2015 1:08am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics