Fix Msg 8116 “Argument data type date is invalid for argument 1 of substring function” in SQL Server

If you’re getting SQL Server error Msg 8116 with text that reads Argument data type date is invalid for argument 1 of substring function, it’s because you’re passing the wrong data type to a function – in this case, the SUBSTRING() function.

You could also see the same error (Msg 8116) in many other contexts – it’s not limited to the SUBSTRING() function.

Continue reading

Fix Msg 8114 “Error converting data type varchar to numeric” in SQL Server

If you’re getting SQL Server error Msg 8114 that reads something like Error converting data type varchar to numeric, it’s probably because you’re trying to perform a data type conversion that fails due to the value not being able to be converted to the destination type.

It’s not because you can’t convert that type to the new type. It’s because of the value itself.

Continue reading

How to Format Numbers with Commas in SQL

Most of the major RDBMSs have functions that enable us to format numbers with commas as either the group separator, or the decimal separator.

Some RDBMSs also output certain numeric data types with commas in the relevant place.

Below are examples of formatting numbers with commas in some of the more popular DBMSs.

Continue reading

Fix “Arithmetic overflow error converting int to data type numeric” in SQL Server

If you’re receiving error Msg 8115, Level 16, Arithmetic overflow error converting int to data type numeric in SQL Server, it’s probably because you’re performing an operation that results in a data conversion error due to an out of range value.

This will often happen when you try to convert a number to a different data type, but it’s out of the accepted range for the new data type.

Continue reading