Published: 2026-09-26 • Updated: 2026-11-06
The Most Common SQL Server Errors, Ranked from Real Query Telemetry
Between 27 July and 25 September 2026, the SQL Server errors that failed queries for the most Jam SQL Studio installations were Msg 102 – Incorrect syntax near (121 installations), Msg 207 – Invalid column name (109) and Msg 208 – Invalid object name (108), out of 359 installations that ran SQL Server queries in that window. Next come 156, 2812, 2714, 4104, 137 and 8120. This post ranks the top 17 from our anonymous app telemetry and, for each of the top nine, gives the exact message SQL Server prints, the causes behind it, and a T-SQL fix. Every example message below was reproduced on SQL Server 2025.
This is the query-side companion to SQL Server connection errors we actually see, which covers the failures that happen before a query is ever sent: Login failed 18456, pre-login handshake errors and connection timeouts.
The ranking: SQL Server errors by installations affected
Over the 60 days, 359 installations completed 41,686 SQL Server queries, and 7,639 SQL Server runs ended in an error, about 15% of all runs. 258 installations (72% of the 359) hit at least one error. The table ranks error numbers by how many installations hit them at least once, not by raw event count, because one person iterating on a broken query can fire the same error dozens of times. Msg 102 averaged almost nine events per affected installation; Msg 2812 averaged 1.4.
| # | Code | Message (as SQL Server prints it) | Installations | Share of 359 | Events | Usual cause |
|---|---|---|---|---|---|---|
| 1 | 102 | Incorrect syntax near '…'. | 121 | 33.7% | 1,073 | Missing comma or parenthesis, syntax from another engine (LIMIT, backticks) |
| 2 | 207 | Invalid column name '…'. | 109 | 30.4% | 859 | Misspelled or renamed column, SELECT alias used in WHERE, column behind the wrong alias in a join, double-quoted string |
| 3 | 208 | Invalid object name '…'. | 108 | 30.1% | 594 | Misspelled or renamed table, missing schema prefix, temp table or CTE out of scope |
| 4 | 156 | Incorrect syntax near the keyword '…'. | 75 | 20.9% | 431 | Reserved word used as a name, trailing comma before FROM, syntax newer than the server |
| 5 | 2812 | Could not find stored procedure '…'. | 36 | 10.0% | 49 | A bare word run as the first statement of a batch, missing schema, a procedure that calls a missing one |
| 6 | 2714 | There is already an object named '…' in the database. | 29 | 8.1% | 153 | Re-running a CREATE script, leftover #temp table, duplicate constraint name |
| 7 | 4104 | The multi-part identifier "…" could not be bound. | 27 | 7.5% | 129 | Table name used after it was aliased, a subquery's alias used outside it, alias typo, ON clause referencing a later table |
| 8 | 137 | Must declare the scalar variable "…". | 26 | 7.2% | 68 | Running a statement without its DECLARE, GO ending the scope, dynamic SQL |
| 9 | 8120 | Column '…' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause. | 25 | 7.0% | 113 | A selected column that is neither grouped nor aggregated |
| 10 | 209 | Ambiguous column name '…'. | 21 | 5.8% | 39 | Unqualified column that exists in two joined tables |
| 11 | 4145 | An expression of non-boolean type specified in a context where a condition is expected, near '…'. | 19 | 5.3% | 52 | A WHERE or ON with a value but no comparison |
| 12 | 195 | '…' is not a recognized built-in function name. | 17 | 4.7% | 27 | A function from another engine (IFNULL), or a scalar UDF called without its schema |
| 13 | 245 | Conversion failed when converting the … value '…' to data type …. | 15 | 4.2% | 35 | A string column compared with a number while non-numeric values are present |
| 14 | 547 | The … statement conflicted with the … constraint "…". … | 12 | 3.3% | 45 | A child row whose parent doesn't exist, or deleting a parent that is still referenced |
| 15 | 266 | Transaction count after EXECUTE indicates a mismatching number of BEGIN and COMMIT statements. … | 11 | 3.1% | 27 | A procedure that opens a transaction and returns without committing or rolling back |
| 16 | 402 | The data types … and … are incompatible in the … operator. | 11 | 3.1% | 22 | Comparing a legacy text/ntext column with = |
| 17 | 206 | Operand type clash: … is incompatible with … | 11 | 3.1% | 15 | A value of an incompatible type, such as an int assigned to a date |
Two notes on reading it. The shares are lower bounds: the app has only attached the server's error number to its error events since version 1.4.25 (29 August 2026), so the per-code counts cover roughly the last four weeks of the window, while the 359 denominator covers all 60 days (details in Methodology). And three driver-level codes are left out because they aren't SQL Server error numbers: EREQUEST (30 installations), the generic wrapper that app versions 1.4.23 and 1.4.24 reported in place of the number; ETIMEOUT (18); and ELOGIN (15), a login failure that belongs to the connection errors post.
What the ranking says
- Four errors lead by a wide margin. Two parse errors (102, 156) and two name-resolution errors (207, 208) were each hit by 75 to 121 installations. Nothing else reached 40.
- Some errors repeat and some happen once. 102 and 207 averaged eight to nine events per affected installation, which is what iterating on a query looks like. 2812 averaged 1.4: a one-off mistake, which fits its most common cause below (running a single word).
- Partial runs are a big share of failures. Across all engines, 53% of failed runs executed a selection or the statement at the cursor rather than the whole editor. That is exactly when a
DECLARE, a CTE header, or the first half of a statement gets left out, which is how 137, 156 and 2812 turn up in a script that looks correct.
Errors where a name doesn't resolve (207, 208, 4104, 2812, 3701)
We looked at the name errors again in a later window, the 30 days to 6 November 2026. In that window, 278 installations ran SQL Server queries in Jam SQL Studio, and 146 of them (53%) hit at least one error where a column, table, alias or procedure name didn't resolve. There were 1,344 such errors, 37% of all SQL Server query errors in the window.
| Code | Message | Errors | Installations |
|---|---|---|---|
| 207 | Invalid column name '…'. | 597 | 98 |
| 208 | Invalid object name '…'. | 538 | 104 |
| 4104 | The multi-part identifier "…" could not be bound. | 144 | 43 |
| 2812 | Could not find stored procedure '…'. | 47 | 26 |
| 3701 | Cannot drop the table '…', because it does not exist or you do not have permission. | 18 | 8 |
The usual first advice for these errors is to check that you are in the right database. Two numbers suggest that is rarely the problem:
- The same error again. 38% of these errors were followed within five minutes by another error with the same code. That is what changing the query slightly, running it again and getting the same error looks like.
- Little looking in other databases. The database selector was opened within five minutes after only 10.8% of these errors. Before version 1.5.9, the only one-click action Jam SQL Studio offered under them was a Switch database… button; in this window it was offered on 815 of these errors and clicked 31 times (3.8%).
The figures come from anonymous usage events sent by the desktop app; installation counts are distinct installations, the five-minute figures are shares of the 1,344 errors, and no query text or object names are collected. That also means the data can't say which cause was behind a given error. The sections below order the causes by how often we expect them, from these numbers and from reproducing each one: the name itself (a typo or a rename), then the schema, aliases and scope, then collation and stored procedures, and the database last. The numbers describe Jam SQL Studio users writing queries in an editor, not all SQL Server users.
1. Msg 102: Incorrect syntax near '…'
Msg 102, Level 15
Incorrect syntax near '10'.What it means: the parser stopped at the quoted token because nothing valid can follow the text before it. The mistake is usually just before the token in the message, not at it. It is a parse error, so nothing in the batch ran and no rows were touched.
Most common causes (each message below is what SQL Server 2025 returned for the example):
- Syntax from another engine.
SELECT * FROM sys.objects LIMIT 10fails with Incorrect syntax near '10': T-SQL has noLIMIT, so the parser readsLIMITas a table alias and chokes on the number. MySQL backticks give Incorrect syntax near '`'. - A missing comma.
SELECT name object_id type FROM sys.objectsgives Incorrect syntax near 'type':name object_idparses as a column with an alias, and the third word has nowhere to go. - A derived table without an alias.
SELECT * FROM (SELECT 1 AS a)gives Incorrect syntax near ')'. Every subquery inFROMneeds a name. - An unescaped quote.
'O'Brien'ends the string afterO; SQL Server reports the companion error Msg 105, Unclosed quotation mark after the character string. Double the quote:'O''Brien'.
-- MySQL/PostgreSQL habits and their T-SQL equivalents
SELECT TOP (10) name FROM sys.objects ORDER BY name;
SELECT name FROM sys.objects
ORDER BY name
OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY; -- paging
SELECT [name], [type] FROM sys.objects; -- brackets instead of backticks
SELECT * FROM (SELECT 1 AS a) AS t; -- alias every derived tableIn Jam SQL Studio, genuine syntax errors on SQL Server are underlined as you type, before anything runs, and a misspelled keyword such as FORM comes with a Quick Fix (Cmd+. / Ctrl+.) that changes it to FROM. The Query Editor guide describes how the check avoids flagging valid SQL.
2. Msg 207: Invalid column name '…'
Msg 207, Level 16, State 1, Line 1
Invalid column name 'Totl'.What it means: the table resolved, but a column name in the statement doesn't match a column of any table the query can see at that point. When the column plainly exists, the cause is usually where the name is used. The message leaves out the prefix: o.Name is reported as Invalid column name 'Name'.
Most common causes, most likely first. Each message is what SQL Server 2025 returned for the example, run in a scratch database with dbo.Customers, dbo.Orders and Sales.Invoices tables:
- A typo, or a renamed column.
SELECT OrderID, Totl FROM dbo.Ordersgives Invalid column name 'Totl'. AfterEXEC sp_rename 'dbo.Customers.Email', 'EmailAddress', 'COLUMN', every query, view and procedure that still saysEmailfails with Invalid column name 'Email'.sp_renamewarns about this when it runs: Caution: Changing any part of an object name could break scripts and stored procedures. - A
SELECTalias used inWHERE.SELECT Total * 1.2 AS gross FROM dbo.Orders WHERE gross > 100fails with Invalid column name 'gross', becauseWHEREis evaluated before the select list.ORDER BY grossworks, becauseORDER BYis evaluated after it. Repeat the expression, wrap the query in a derived table, or compute the value inCROSS APPLY(example below). - A column behind the wrong alias in a join. In
SELECT o.OrderID, o.Name FROM dbo.Orders AS o JOIN dbo.Customers AS c ON c.CustomerID = o.CustomerID,Nameis a column ofCustomers, but the prefix saysOrders, so the query fails with Invalid column name 'Name'. Writec.Name. - A string in double quotes. With
QUOTED_IDENTIFIERON,WHERE Name = "Smith"looks for a column calledSmithand fails with Invalid column name 'Smith'. ON is the default in SSMS and in most drivers.sqlcmdis the exception: it connects with the setting OFF unless you pass-I, so the same line can work in asqlcmdscript and fail in an editor. String literals take single quotes:'Smith'. - A column added earlier in the same batch.
ALTER TABLE dbo.Orders ADD Note varchar(10); UPDATE dbo.Orders SET Note = 'x';run as one batch fails with Invalid column name 'Note', and the column isn't added either: the whole batch is compiled before theALTERruns. PutGObetween the two statements. - A case-sensitive collation. Names follow the database's collation. In a database created with
COLLATE Latin1_General_100_CS_AS,SELECT orderid FROM dbo.Ordersgives Invalid column name 'orderid'.SELECT DATABASEPROPERTYEX(DB_NAME(), 'Collation')shows the collation;_CS_in its name means case-sensitive. - Inside a stored procedure. A procedure created while its table didn't exist yet is saved without its columns being checked (deferred name resolution). If the table later appears with other columns, the error waits for the first run: Msg 207, Level 16, State 1, Procedure dbo.usp_Archive, Line 1: Invalid column name 'ArchivedAt'. When the table already exists,
CREATE PROCEDUREitself reports the 207. AProcedurepart in the message means the fix is in that procedure, not in theEXECyou ran. - Right query, wrong database. A table with the same name exists in the database you're connected to, but it's an older copy with different columns: dev versus staging, or a restored backup. Selecting
OrderDatefrom such a copy gives Invalid column name 'OrderDate'.
-- Which columns does the table have, in the database this query runs in?
SELECT DB_NAME() AS current_db, name
FROM sys.columns
WHERE object_id = OBJECT_ID('dbo.Customers');
-- Alias in WHERE: compute the value once in CROSS APPLY
SELECT o.OrderID, g.gross
FROM dbo.Orders AS o
CROSS APPLY (SELECT o.Total * 1.2 AS gross) AS g
WHERE g.gross > 100;
-- Schema change and use of the new column: two batches
ALTER TABLE dbo.Orders ADD Note varchar(10);
GO
UPDATE dbo.Orders SET Note = 'x';In Jam SQL Studio 1.5.9 and later, a misspelled column such as Totl gets Did you mean Total? and a Replace with Total button; most of the other causes keep a tip to check the spelling and which table the column belongs to. What the app shows has the details.
3. Msg 208: Invalid object name '…'
Msg 208, Level 16, State 1, Line 1
Invalid object name 'dbo.Custmers'.What it means: a table, view or table-valued function in the statement can't be found from the current database and schema. It's the same family as 207, one level up. The message repeats the name as you wrote it, schema included, which is often enough to spot the first two causes.
Most common causes, most likely first (same scratch database):
- A typo, or a renamed table.
SELECT * FROM dbo.Custmersgives Invalid object name 'dbo.Custmers'. AfterEXEC sp_rename 'dbo.OrderLines', 'OrderItems',SELECT * FROM dbo.OrderLinesgives Invalid object name 'dbo.OrderLines', and so does every view and procedure that still uses the old name. - The wrong schema, or none. An unqualified name is looked up in your default schema and then
dbo. With the table inSales,SELECT * FROM Invoicesfails with Invalid object name 'Invoices', andSELECT * FROM dbo.Invoiceswith Invalid object name 'dbo.Invoices'. WriteSales.Invoices. - A temp table or CTE out of scope. A
#temptable created insideEXEC('…')is dropped when that dynamic batch ends:EXEC (N'CREATE TABLE #recent (OrderID int);'); SELECT * FROM #recent;gives Invalid object name '#recent'. Create the table in the outer batch, and the dynamic SQL can fill it. A#temptable created in another session, such as another editor tab, was never visible to you. A CTE exists for exactly one statement: inWITH big AS (…) SELECT COUNT(*) AS n FROM big; SELECT * FROM big;the secondSELECTfails with Invalid object name 'big'. - A case-sensitive collation. In a database with a
_CS_collation,SELECT * FROM dbo.ordersgives Invalid object name 'dbo.orders' when the table isOrders. - Deferred name resolution in a stored procedure.
CREATE PROCEDUREaccepts a table that doesn't exist:CREATE PROCEDURE dbo.usp_Report AS SELECT OrderID FROM dbo.OrderHistory;succeeds without a warning, and the error appears when someone runs it: Msg 208, Level 16, State 1, Procedure dbo.usp_Report, Line 1: Invalid object name 'dbo.OrderHistory'. As with 207, theProcedurepart tells you where to look. - The wrong database. It's the usual first advice, and it comes last here. A login lands in its default database, often
master, and the query runs there:SELECT * FROM dbo.Ordersinmastergives Invalid object name 'dbo.Orders'.SELECT DB_NAME()shows where the query ran;USE, the editor's database selector, or a three-part name such asShop.dbo.Ordersfixes it.
-- Where does the query run, and which schema holds the table?
SELECT DB_NAME() AS current_db, SCHEMA_NAME() AS default_schema;
SELECT SCHEMA_NAME(schema_id) AS schema_name, name, type_desc
FROM sys.objects
WHERE name LIKE '%Invoice%' AND type IN ('U', 'V');
-- Qualify the name: schema.object, or database.schema.object
SELECT TOP (10) * FROM Sales.Invoices;
SELECT TOP (10) * FROM Shop.dbo.Orders;
-- A #temp table that dynamic SQL fills: create it in the outer batch
CREATE TABLE #recent (OrderID int);
EXEC (N'INSERT #recent VALUES (10);');
SELECT OrderID FROM #recent;What Jam SQL Studio shows under these errors
In Jam SQL Studio 1.5.9 and later, a table, view, column or alias that doesn't resolve gets a Did you mean …? tip under the error. The names come from the schema IntelliSense has already loaded for the tab's connection and database, so no extra query runs. On SQL Server this covers 207, 208 and 4104:
- A near name. A table or column one or two typing mistakes away (one for names of up to four characters), or the same name with an underscore or a plural ending added or dropped:
dbo.Custmersgets Did you mean Customers? When more than one name is close, up to three are listed, closest first: Did you mean one of: …? - The exact name in another schema.
Invoicesgets Did you mean Sales.Invoices? - A column is matched against the columns of the tables the statement reads, and only against the aliased table's columns when it has a prefix:
o.OrderDatgets Did you mean OrderDate? - An alias that matches nothing in the statement (4104) gets the statement's aliases:
od.OrderIDwithFROM dbo.Orders AS ogets Did you mean o? - The exact table in another database. When the table exists, in the schema the query names, only in another database on the same connection whose schema IntelliSense has loaded, the tip says so: Tip: Orders exists in the Shop database — switch the tab to it to run this query there. A Switch to Shop button switches the tab to that database. If the tab has an open transaction, it asks first.
When there is one best match and the misspelled name appears once in the query, a Replace with … button writes the name into the editor as a single undo step, in brackets where SQL Server needs them (a reserved word such as Order). It doesn't run the query; you run it yourself. If you edit the query after the run, Replace leaves the text alone and asks you to run the query again for a fresh suggestion.
Several causes above get no suggestion:
- nothing in the schema is close enough, which is usually the case for a table renamed to something quite different, a
#temptable, a CTE, aSELECTalias used inWHEREand a string in double quotes; - the name differs only in case under a case-sensitive collation, because the suggestion compares SQL Server names without regard to case;
- the prefix does name a table in the statement: a column behind the wrong alias (
o.Name), or a 4104 for a table name used after aliasing, a subquery's alias used outside it, or anONclause that looks ahead; - 2812 and 3701, because suggestions cover tables, views, columns and aliases, not procedures;
- right after connecting, before IntelliSense has loaded the schema.
Then the tip from earlier versions stays. For 208, 2812 and 3701 it says the object may exist in a different database or schema, with a Switch database… button that opens the tab's database selector. For 207 and 4104 it says to check the spelling and which table the column belongs to, with no button, because the table itself was found. The same suggestions work on PostgreSQL, MySQL, Oracle and SQLite; the Query Editor guide has the details for each engine.
4. Msg 156: Incorrect syntax near the keyword '…'
Msg 156, Level 15
Incorrect syntax near the keyword 'FROM'.What it means: the same parse failure as 102, except the token where the parser stopped is a reserved keyword. That makes it easier to locate: look at what comes right before the keyword.
Most common causes:
- A trailing comma before
FROM.SELECT name, FROM sys.objectsgives Incorrect syntax near the keyword 'FROM', the usual leftover after deleting the last column from a list. - A reserved word used as a name. A column called
order,userorkeyfails unquoted:SELECT order FROM dbo.Salesgives Incorrect syntax near the keyword 'order'. Bracket it:[order]. - Running a fragment. Executing only the tail of a statement, such as
SalesOrderHeader WHERE 1=1, gives Incorrect syntax near the keyword 'WHERE'. Select the whole statement. - Syntax newer than the server.
DROP TABLE IF EXISTSarrived in SQL Server 2016; on 2014 and older it fails with Incorrect syntax near the keyword 'IF'. CheckSELECT @@VERSIONbefore assuming the syntax is wrong.
A near relative: starting a CTE right after another statement without a semicolon is reported as Msg 319, Incorrect syntax near the keyword 'with'. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a semicolon. The fix is in the message: end the previous statement with ;.
SELECT [order], [user] FROM dbo.Sales; -- bracket reserved words
IF OBJECT_ID('dbo.Staging', 'U') IS NOT NULL -- pre-2016 form of DROP ... IF EXISTS
DROP TABLE dbo.Staging;5. Msg 2812: Could not find stored procedure '…'
Msg 2812, Level 16, State 62, Line 1
Could not find stored procedure 'Custmers'.What it means: SQL Server tried to execute a procedure by that name and found none. Often nobody meant to call a procedure at all.
Most common causes, most likely first:
- A bare word at the start of a batch. The
EXECkeyword is optional when a procedure call is the first statement in a batch, so a batch that consists of the single wordCustmersis read asEXEC Custmers. Select one word in the editor, such as a misspelled table name or a CTE name, run just the selection, and you get exactly this. If the word names an existing table or view, the message changes to Msg 2809, The request for procedure 'Customers' failed because 'Customers' is a table object. This fits the telemetry: 2812 is spread across many installations but rarely repeats. - The procedure is in another schema. Like tables, an unqualified procedure name isn't found outside your default schema and
dbo. With the procedure inSales,EXEC usp_GetInvoicesgives Could not find stored procedure 'usp_GetInvoices'. Call it asEXEC Sales.usp_GetInvoices. - A procedure that calls a missing one.
CREATE PROCEDURE dbo.usp_Nightly AS EXEC dbo.usp_Cleanup;is created with an informational message, The module 'usp_Nightly' depends on the missing object 'dbo.usp_Cleanup'. The module will still be created; however, it cannot run successfully until the object exists. Running it gives Msg 2812, Level 16, State 62, Procedure dbo.usp_Nightly, Line 1: Could not find stored procedure 'dbo.usp_Cleanup'. The missing procedure is the inner one. - It lives in another database. Utility procedures are often installed once, in
masteror a DBA database, and called from elsewhere. Qualify it asEXEC DBA.dbo.usp_Nameor switch database.
-- Does it exist, and under which schema?
SELECT SCHEMA_NAME(schema_id) AS schema_name, name
FROM sys.procedures
WHERE name LIKE '%GetInvoices%';
EXEC Sales.usp_GetInvoices;Jam SQL Studio doesn't suggest procedure names: under 2812 it shows the tip about another database or schema and the Switch database… button (details).
6. Msg 2714: There is already an object named '…' in the database
Msg 2714, Level 16
There is already an object named '#dup' in the database.What it means: a CREATE (or SELECT … INTO) tried to make an object whose name is taken. In a query editor it almost always means a script was run twice.
Most common causes:
- Re-running a setup script. The first run created the table; the second fails at the same line.
- A
#temptable from the previous run. A local temp table lives until the session ends. RunCREATE TABLE #dup …twice on the same connection and the second run fails with the message above. - A duplicate constraint name. Constraint names are objects in the schema, not per-table labels. Creating a second table with
CONSTRAINT PK_Orders PRIMARY KEYfails with 2714 forPK_Orders, followed by Msg 1750, Could not create constraint or index. See previous errors.
DROP TABLE IF EXISTS #dup; -- SQL Server 2016+
CREATE TABLE #dup (id int);
CREATE OR ALTER VIEW dbo.ActiveCustomers AS -- 2016 SP1+: procedures, views, functions, triggers
SELECT CustomerID FROM dbo.Customers WHERE IsActive = 1;
GO
IF OBJECT_ID('dbo.AuditLog', 'U') IS NULL -- tables have no CREATE OR ALTER
CREATE TABLE dbo.AuditLog (id int CONSTRAINT PK_AuditLog PRIMARY KEY);7. Msg 4104: The multi-part identifier “…” could not be bound
Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "Orders.OrderID" could not be bound.What it means: the prefix before the dot, a table name or alias, doesn't match anything available at that point in the query. The column may be fine; the prefix isn't. A wrong column behind a valid prefix is a 207 instead.
Most common causes, most likely first:
- The table name used after aliasing.
SELECT Orders.OrderID FROM dbo.Orders AS ofails with the message above: once a table has an alias, only the alias works. Writeo.OrderID. - An alias used outside its scope. An alias defined inside a subquery isn't visible outside it.
SELECT o.OrderID FROM (SELECT OrderID FROM dbo.Orders AS o) AS dgives The multi-part identifier "o.OrderID" could not be bound; the outer query sees onlyd, so writed.OrderID. - An alias typo.
SELECT od.OrderID FROM dbo.Orders AS ogives The multi-part identifier "od.OrderID" could not be bound. - An
ONclause that looks ahead. In… JOIN Sales.Invoices AS i ON i.OrderID = o.OrderID AND c.CustomerID = o.CustomerID JOIN dbo.Customers AS c …,c.CustomerIDfails becausecis joined later. AnONclause can only see tables joined before it; move the condition to the later join. - A table that isn't in
FROM. Common inUPDATE:UPDATE dbo.Orders SET Total = 0 WHERE Customers.Name = 'Smith'gives The multi-part identifier "Customers.Name" could not be bound, becauseCustomersis never joined. Join it in anUPDATE … FROM.
-- A filter on another table: join it in UPDATE ... FROM
UPDATE o SET Total = 0
FROM dbo.Orders AS o
JOIN dbo.Customers AS c ON c.CustomerID = o.CustomerID
WHERE c.Name = 'Smith';In Jam SQL Studio 1.5.9 and later, a prefix that matches no table or alias anywhere in the statement gets the statement's aliases, and the names of tables without one, as the suggestion: od.OrderID gets Did you mean o? and a Replace with o button. When the prefix does name a table or alias somewhere in the statement, as in the first, second and fourth causes, the tip says to check the spelling and which table the column belongs to (details).
8. Msg 137: Must declare the scalar variable “@…”
Msg 137, Level 15
Must declare the scalar variable "@CustomerId".What it means: a statement uses a variable that doesn't exist in the batch that was sent. Variables are scoped to one batch.
Most common causes:
- Running only part of the script. Execute the statement at the cursor, or a selection, and the
DECLAREthree lines up isn't sent. In Jam SQL Studio,Cmd/Ctrl+Enterruns just the current statement, so select theDECLAREtogether with the statement, or run the whole script. - A
GObetween declaration and use.GOends the batch, and the variable with it. - Dynamic SQL.
EXEC sp_executesql N'SELECT @id'fails with Must declare the scalar variable "@id" even when the caller declared@id; the dynamic batch has its own scope. - A table variable used like a table name.
WHERE @t.id = 1fails with Must declare the scalar variable "@t". Give the table variable an alias.
DECLARE @id int = 5;
EXEC sp_executesql N'SELECT @id AS id', N'@id int', @id = @id;
DECLARE @t TABLE (id int);
SELECT * FROM @t AS t WHERE t.id = 1;9. Msg 8120: Column is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause
Msg 8120, Level 16
Column 'sys.objects.name' is invalid in the select list because it is not
contained in either an aggregate function or the GROUP BY clause.What it means: with GROUP BY, each output row stands for a group, and a selected column that is neither grouped nor aggregated has no single value for that row. SQL Server refuses to pick one. MySQL with ONLY_FULL_GROUP_BY turned off does pick one, which is why this error often shows up in queries ported from MySQL.
Fixes, depending on what you meant:
-- 1. The column is part of the grouping
SELECT type, name, COUNT(*) AS n FROM sys.objects GROUP BY type, name;
-- 2. Any one value per group is fine: aggregate it
SELECT type, MIN(name) AS first_name, COUNT(*) AS n
FROM sys.objects GROUP BY type;
-- 3. You want every row plus the group total: a window function
SELECT type, name, COUNT(*) OVER (PARTITION BY type) AS n_in_type
FROM sys.objects;Its sibling Msg 8127 (10 installations) is the same rule applied to ORDER BY: Column "sys.objects.name" is invalid in the ORDER BY clause because it is not contained in either an aggregate function or the GROUP BY clause.
Errors 10 to 17: short fixes
| Code | Example message (SQL Server 2025) | Fix |
|---|---|---|
| 209 | Ambiguous column name 'name'. | Both joined tables have the column; prefix it with the alias: o.name. |
| 4145 | An expression of non-boolean type specified in a context where a condition is expected, near 'object_id'. | WHERE object_id needs a comparison: WHERE object_id IS NOT NULL or = 1. T-SQL doesn't treat a value as true or false. |
| 195 | 'IFNULL' is not a recognized built-in function name. | Use the T-SQL function (ISNULL or COALESCE). A scalar user-defined function must be called with its schema: dbo.ufnGetStock(1), not ufnGetStock(1). |
| 245 | Conversion failed when converting the varchar value 'abc' to data type int. | Comparing a string column with a number converts the column; one non-numeric row fails the query. Compare with a string, or use TRY_CAST(col AS int). |
| 547 | The INSERT statement conflicted with the FOREIGN KEY constraint "FK_…". The conflict occurred in database "…", table "…", column 'id'. | Insert the parent row first. For a DELETE (“conflicted with the REFERENCE constraint”), delete or re-point the child rows first. Also raised by CHECK constraints. |
| 266 | Transaction count after EXECUTE indicates a mismatching number of BEGIN and COMMIT statements. Previous count = 1, current count = 2. | The procedure opened a transaction and returned without COMMIT or ROLLBACK. Close it on every path, including the CATCH block. |
| 402 | The data types text and varchar are incompatible in the equal to operator. | Legacy text/ntext columns can't be compared with =. Cast to varchar(max)/nvarchar(max), or use LIKE; better, migrate the column. |
| 206 | Operand type clash: int is incompatible with date | The value's type can't be converted to the target at all (DECLARE @d date = 5). Pass a date literal such as '2026-09-26', or fix the parameter type. |
Methodology
- Source and window. Jam SQL Studio's anonymous in-app usage events, 27 July to 25 September 2026 (60 days). A failed query sends one event carrying the engine, an error category, the error code (
208,42P01,ORA-00942), how the run was started (toolbar, shortcut, selection, statement at cursor), its duration, and which one-click fix was shown, if any. A successful query sends a separate event with the engine and timing. - What is not collected. No SQL text, no error message text, no table, column, schema or database names, no hostnames. The code field only accepts short identifier-shaped tokens. Usage analytics can be turned off in Settings → Privacy, and installations that did so are not in these numbers. The privacy policy describes the telemetry.
- Installations, not people. Each installation sends an anonymous identifier derived from a hashed device fingerprint. One person on two machines counts twice; two people sharing a machine count once.
- Sample. 359 installations completed at least one SQL Server query (41,686 successful runs); 7,639 SQL Server runs failed.
- Name errors, later window. The figures in Errors where a name doesn't resolve come from the same kind of events over the 30 days to 6 November 2026, when 278 installations ran SQL Server queries. The five-minute figures look at what the same installation did next: its next error, and whether it opened the database selector.
- Error numbers are recent. The server's error number has been attached since version 1.4.25 (29 August 2026). Before 1.4.23 the events carried only a category, and 1.4.23 and 1.4.24 usually reported the driver's generic
EREQUESTcode instead of the number. 2,830 of the 7,639 SQL Server error events (37%) carry no code at all. The per-code counts therefore come mostly from the last four weeks, from installations that had updated, and the shares against 359 are lower bounds. The ranking between codes is the useful part. - Ranked by installations. Installations are counted once per code, so a single installation that retried the same broken query many times doesn't move the ranking. Event counts are shown alongside.
- Who is in the sample. These are people using a desktop SQL editor: mostly developers and analysts writing ad-hoc queries. Errors made while typing and iterating count the same as errors in finished scripts. An application's error log, full of tested, parameterized queries, would look different, with more deadlocks, timeouts and constraint violations.
Appendix: the same ranking on PostgreSQL, MySQL and Oracle
Same window and method. The pattern repeats on every engine: a parse error, an unknown table and an unknown column fill the top three places.
PostgreSQL (131 installations ran queries, 74 hit an error)
| SQLSTATE | Example message | Installations | Usual cause |
|---|---|---|---|
42601 syntax_error | syntax error at or near "…" | 26 | Typos, T-SQL habits (TOP, brackets), a statement cut short |
42P01 undefined_table | relation "films" does not exist | 26 | Schema missing from search_path; a table created with a quoted mixed-case name ("Film") queried unquoted, or the reverse |
42703 undefined_column | column "titel" does not exist | 15 | Typos and the same quoted-case trap; a double-quoted string meant as a literal |
42P07 duplicate_table | relation "…" already exists | 8 | Re-running a CREATE; use CREATE TABLE IF NOT EXISTS |
42883 undefined_function | function lenght(character varying) does not exist | 6 | A misspelled function, or argument types with no matching overload (add a cast) |
42803 grouping_error | column "film.title" must appear in the GROUP BY clause or be used in an aggregate function | 5 | The PostgreSQL form of SQL Server's 8120 |
23505 unique_violation | duplicate key value violates unique constraint "…" | 5 | Inserting a key that already exists |
MySQL (157 installations ran queries, 113 hit an error)
| Error | Example message | Installations | Usual cause |
|---|---|---|---|
ER_PARSE_ERROR (1064) | You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '5 * FROM film' at line 1 | 75 | Typos and other dialects' syntax (that example is SELECT TOP 5) |
ER_BAD_FIELD_ERROR (1054) | Unknown column 'titel' in 'field list' | 53 | Misspelled column, or a double-quoted value read as a name under ANSI_QUOTES |
ER_NO_SUCH_TABLE (1146) | Table 'sakila.films' doesn't exist | 53 | Wrong database selected (the message names the one it looked in), or table-name case on a case-sensitive file system |
ER_BAD_DB_ERROR (1049) | Unknown database 'sakilla' | 36 | A misspelled USE, or a database that was renamed or dropped |
ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT (1582) | Incorrect parameter count in the call to native function 'IFNULL' | 14 | Wrong number of arguments to a built-in function |
ER_NO_DB_ERROR (1046) | No database selected | 9 | A connection with no default database and an unqualified table name |
MySQL also had a driver-level ETIMEDOUT for 23 installations, a connection problem rather than a query error.
Oracle (69 installations ran queries, 55 hit an error)
| Error | Example message (Oracle 23.26) | Installations | Usual cause |
|---|---|---|---|
ORA-00942 | table or view "JAMSQL"."NO_SUCH_TABLE" does not exist | 15 | Table in another schema (qualify it as OWNER.TABLE), or a missing grant: Oracle reports an object you can't access as not existing |
ORA-00900 | invalid SQL statement | 12 | Client commands that aren't SQL, such as SQL*Plus DESC or SHOW USER, or USE from other engines |
ORA-00904 | "DUMY": invalid identifier | 8 | Misspelled column, or a column created with a quoted mixed-case name |
ORA-00936 | missing expression | 5 | An empty select list or a dangling operator, such as SELECT FROM dual |
ORA-00933 | SQL command not properly ended | 4 | Extra text after a complete statement; newer releases often report ORA-03048 instead, naming the unexpected word |
Left out of the Oracle list: ORA-01435 user does not exist (4 installations), which the app's own schema switch can trigger through ALTER SESSION SET CURRENT_SCHEMA, and ORA-01013 (4), which is a user cancelling a query rather than a query error.
Quick Answers
Short answers to the questions this post covers.
Q: What is the most common SQL Server error?
A: In Jam SQL Studio's anonymous telemetry from 27 July to 25 September 2026, Msg 102 'Incorrect syntax near' failed queries for the most installations: 121 of the 359 that ran SQL Server queries (33.7%). Msg 207 'Invalid column name' (109 installations) and Msg 208 'Invalid object name' (108) were close behind, followed by Msg 156 'Incorrect syntax near the keyword' (75). Error numbers were only recorded from 29 August, so these shares are lower bounds.
Q: How do I fix 'Invalid object name' (Msg 208) in SQL Server?
A: Check the name before the database. In order of likelihood: a typo, or a table that was renamed; the schema, because an unqualified name is looked up only in your default schema and then dbo, so a table in Sales needs Sales.Invoices; scope, because a #temp table created inside dynamic SQL or in another session, or a CTE referenced after its statement, no longer exists; a case-sensitive collation, under which Orders and orders are different names; and a stored procedure created before its table existed, which fails only when it runs. Check the database last: SELECT DB_NAME() shows which one the query ran in.
Q: Is 'Invalid object name' usually caused by being in the wrong database?
A: Less often than the usual advice suggests. In Jam SQL Studio's anonymous telemetry for the 30 days to 6 November 2026, 38% of SQL Server name errors (207, 208, 4104, 2812 or 3701) were followed within five minutes by another error with the same code, while the database selector was opened within five minutes after only 10.8% of them. A Switch database button shown under 815 of these errors was clicked 31 times (3.8%). Typos, missing schema prefixes, aliases and scope explain most of them.
Q: Why does SQL Server say 'Invalid column name' when the column exists?
A: Usually because of where the name is used, not whether it exists. A column alias defined in SELECT can't be used in WHERE, because WHERE is evaluated first. In a join, a column written behind the wrong table's alias isn't found, even though the other table has it. A value in double quotes is read as a column name while QUOTED_IDENTIFIER is ON, the default in SSMS and most drivers. A column added with ALTER TABLE earlier in the same batch isn't visible yet, because the whole batch is compiled before it runs, so put GO between the two statements. Under a case-sensitive collation, OrderID and orderid are different names.
Q: What does 'The multi-part identifier could not be bound' mean?
A: Msg 4104 means the prefix in a name like o.CustomerID or Orders.CustomerID doesn't match any table or alias available at that point in the query. The usual causes are using the table name after giving the table an alias (once aliased, only the alias works), using an alias from inside a subquery in the outer query, a typo in the alias, or an ON clause that references a table joined later in the query.
Q: Why do I get 'Could not find stored procedure' when I didn't call one?
A: When the first statement in a batch is a bare name, SQL Server treats it as a stored procedure call, because the EXEC keyword is optional there. Running a selection that contains only a word such as Custmers produces Msg 2812; if the word names an existing table or view, you get Msg 2809 instead. Run the full SELECT statement, and call real procedures as EXEC schema.procedure_name.
Q: Why does SQL Server say 'Must declare the scalar variable' when the DECLARE is right above?
A: A variable lives for one batch. If you run only the statement that uses it, the DECLARE line is never sent. A GO line between the two also ends the variable's scope, and dynamic SQL run with sp_executesql can't see the caller's variables unless you pass them as parameters. Run the DECLARE together with the statement, or pass the value into sp_executesql explicitly.
The takeaway
Most failed SQL Server queries in our data come down to three checks: read the text just before the token in a syntax error; when a name isn't found, check its spelling, its schema and which table or alias it sits behind before you check the database; and make sure the batch you ran contains everything the statement needs. The rest of the top 17 are specific enough that the message names the fix once you know how to read it. For errors that happen before a query is sent, see the companion post on SQL Server connection errors; for the editor itself, see Jam SQL Studio for SQL Server.
A SQL Server Editor That Explains Failed Queries
Jam SQL Studio underlines syntax errors before you run, adds a tip under common query errors, and suggests the closest existing name when a table or column isn't found. Free for personal use.
Jam SQL Studio