Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

SQL Server error 207 means the query refers to a column name that SQL Server cannot resolve in that context. Check that the query uses the intended database, schema, table and spelling first; then investigate case sensitivity, alias scope or a MERGE source-row issue if the name exists. Microsoft’s error 207 reference identifies these as common causes.

1. Verify the database object and column name

Start with the identifier SQL Server reports. Confirm that the query is running against the intended database and that the table and schema in its FROM or JOIN clauses are the ones you expect. A column can exist on one table but not on another table with a similar name.

To inspect the columns defined for a specific object, run this query with the actual schema and table names:

SELECT name
FROM sys.columns
WHERE object_id = OBJECT_ID('schema_name.table_name');

Compare the returned names with the query character by character. Correct misspellings, references to columns that do not exist on that object, and mistaken schema or database context before changing other parts of the statement.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

2. Check whether the database treats identifier case as significant

If the column exists but SQL Server still rejects its spelling, check the database collation. Microsoft documents this query to retrieve it:

SELECT collation_name
FROM sys.databases
WHERE name = 'database_name';

Replace database_name with the database being queried. A collation name containing CS indicates case sensitivity. In that database, a column defined as LastName is different from Lastname or lastname; use the exact casing shown by the object’s metadata.

3. Check whether a SELECT alias is used before it exists

A name may look like a column but actually be an alias introduced in the SELECT list. SQL Server processes clauses in this logical order: FROM, ON, JOIN, WHERE, GROUP BY, WITH CUBE or WITH ROLLUP, HAVING, SELECT, DISTINCT, ORDER BY, then TOP. Because WHERE and GROUP BY are processed before SELECT, they cannot refer to an alias defined there.

Repeat the expression in the earlier clause

For example, this query defines Year in SELECT and then tries to use it in GROUP BY:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
SELECT DATEPART(yyyy, OrderDate) AS Year,
       SUM(TotalDue) AS Total
FROM Sales.SalesOrderHeader
GROUP BY Year;

Use the expression itself in the earlier clause instead:

SELECT DATEPART(yyyy, OrderDate) AS Year,
       SUM(TotalDue) AS Total
FROM Sales.SalesOrderHeader
GROUP BY DATEPART(yyyy, OrderDate);

Apply the same approach in WHERE when the alias is defined in SELECT: use the underlying expression, not the later alias.

Expose the expression through a derived table

If repeating a longer expression is undesirable, calculate it in a derived table in FROM, then refer to its output column from the outer query. The outer query can group or filter on that derived-table column because it is an input to the outer query rather than a later SELECT alias.

SELECT q.Year,
       SUM(q.TotalDue) AS Total
FROM (
    SELECT DATEPART(yyyy, OrderDate) AS Year,
           TotalDue
    FROM Sales.SalesOrderHeader
) AS q
GROUP BY q.Year;
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

4. Inspect MERGE logic that uses WHEN NOT MATCHED BY SOURCE

Error 207 can also occur in a MERGE statement when a WHEN NOT MATCHED BY SOURCE clause refers to source columns that are unavailable because the source query returns no rows. Review whether the target-side action in that clause actually needs the source value. Adjust the source search condition so the clause has an available source row, or make the target update expression independent of that unavailable source column.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose the check that matches the failing reference

  • Column appears in a table reference: verify the active database, schema, table and column spelling.
  • Column exists but casing differs: inspect the database collation and match exact casing if it is case-sensitive.
  • Name is a SELECT alias used in WHERE or GROUP BY: repeat the expression or expose it through a derived table.
  • Name appears in WHEN NOT MATCHED BY SOURCE: check whether the MERGE source can return no rows and whether the clause depends on a source value.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.