SQL Server Error 4104: The multi-part identifier could not be bound.

If you get an error telling you that the “The multi-part identifier could not be bound.”, it usually means that you’re prefixing one or more columns with either a table that isn’t included in your query, or an alias that you haven’t actually assigned to a table.

Fortunately, the error message shows you which multi-part identifier is causing the problem.

Continue reading

SQL Server Error 109: There are more columns in the INSERT statement than values specified in the VALUES clause

This is a commonly encountered error in SQL Server when inserting data into a table. The full error goes like this:

Msg 109, Level 15, State 1, Line 1
There are more columns in the INSERT statement than values specified in the VALUES clause. The number of values in the VALUES clause must match the number of columns specified in the INSERT statement.

This happens when you specify more columns in the INSERT statement than the number of values that you’re trying to insert with the VALUES clause.

This will occur if you accidentally omit one or more values from the VALUES clause.

You’d get a similar (but technically different) error if you tried to do the opposite – specify fewer columns in the INSERT statement than you try to insert.

Continue reading

How to Fix the “datediff function resulted in an overflow” Error in SQL Server

This article provides a solution to a problem you may occasionally encounter while using the DATEDIFF() function in SQL Server.

If you encounter the following error:

The datediff function resulted in an overflow. The number of dateparts separating two date/time instances is too large. Try to use datediff with a less precise datepart.

It’s because the return value is too large. The DATEDIFF() function returns its result as an int data type. The reason you got this message is that the return value is too big for the int data type. Fortunately there’s an easy way to fix this.

Continue reading