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

SQL Server SHOW TABLES Equivalent

Every now and then I find myself typing SHOW TABLES in SQL Server, expecting to get a list of tables.

That would make perfect sense if I was using MySQL or MariaDB. But SQL Server/T-SQL doesn’t have a SHOW TABLES statement like MySQL or MariaDB, so it never works. And I keep forgetting. But fortunately, SQL Server does have alternatives.

Here are five options for getting a list of tables in SQL Server. These can be used whenever you’re trying to find that elusive SHOW TABLES statement in SQL Server.

Continue reading