Fun With Implicit Conversions

Bert Wagner takes us through some cases where the data type makes your floating point division results quite different:

Let’s start with this example:
SELECT 4.4/CAST(.44 AS VARCHAR(5))

Ignoring for a moment that our denominator is of type VARCHAR, if we do some quick mental math or use a calculator, we can see that the answer should be 10:

Spoilers: it isn’t 10, and Bert explains why.

Related Posts

PARSE, CAST, and CONVERT

Max Vernon gives us three ways to change data types: PARSE provides a mechanism to convert a wide variety of character based dates into a datetime data type. From the Docs: Returns the result of an expression, translated to the requested data type in SQL Server. Use PARSE only for converting from string to date/time and number […]

Read More

Data Type Conversions in Predicates

Bert Wagner takes us through a troublesome table design: This table stores data for an application that has many different types of Pages. Each Page stores different types of data, but instead of creating a separate table for each type, we store all the different data in the varchar DataValue column and maintain the original data type […]

Read More

Categories

April 2019
MTWTFSS
« Mar May »
1234567
891011121314
15161718192021
22232425262728
2930