I am dividing some integers x &lifier y in MS SQL, and that i wan the end result to stay in a floating-point form. 5/2 should equal 2.5. After I function

SELECT 5/2

I recieve 2, which does not suprise me, becasue it is creating an int from two ints. I understand I'm able to pressure it to some float by doing:

SELECT CAST(5 AS FLOAT)/CAST(2 AS FLOAT);

but that appears like overkill. I've found will be able to just like easily (plus much more readably) obtain the same result by utilizing

SELECT (0.0+5)/2;

I am speculating that case some kind of implicit type-casting? Can there be some reason either technique is better/worse?

Underneath the covers there is no difference in implementation. The implicit casts accomplish exactly the same factor as the explicit casts.

Because you write ., TSQL translates this as float value. All following ints are unconditionally cast to drift.

See even the implicit data type conversion matrix within the section Implicit Conversions

Unsure something being shorter is much more readable since true reading through involves comprehension.

SELECT CAST(5 AS FLOAT)/CAST(2 AS FLOAT);

There is really without doubt exactly what the intention is here now and will also be understood whenever you return towards the code 6 several weeks from now or when another developer examines it the very first time.