Fix “date is incompatible with int” in SQL Server when Adding to or Subtracting from a Date

If you’re getting error message “Msg 206” that reads “Operand type clash: date is incompatible with int” in SQL Server while trying to add to (or subtract from) a date, it’s probably because you’re trying to perform arithmetic between an integer and a date value.

To fix this issue, either change the date value to a datetime value or use the DATEADD() function.

Continue reading

How to Get Values That Don’t Contain Numbers in SQL Server

If you have a column in a SQL Server database table that contains character data, but some rows also contain numbers within that data, you can use the following technique to return just those rows that don’t contain numbers.

Numbers can be represented by words and other symbols, but for the purpose of this article, “number” means “numerical digit”. So we’re finding values that don’t contain any numerical digits.

Continue reading

3 Ways to Delete Duplicate Rows in SQL Server while Ignoring the Primary Key

The following examples use T-SQL to delete duplicate rows in SQL Server while ignoring the primary key or unique identifier column.

More specifically, the examples delete duplicate rows but keep one. So, given two identical rows, one is deleted and the other remains. This is often referred to as “de-duping” the table, “deduplication” of the table, etc.

Continue reading