Consider the following error message.

Msg 207 Level 16 State 1 Line 7

Invalid column name 'FOO'.

Because of how I trigged it, I happen to know that is was a parse/compile time error.

Suppose that I was running a long script that was not part of a procedure and I got this same error message. What in this error message tells me that the error was at parse/compile time rather than run time?

CREATE TABLE Department_History
    DepartmentNumber INT

ALTER TABLE Department_History ADD FOO INT;

-- This is fine and shows FOO.
SELECT * FROM Department_History;

-- When uncommented, this fails at parse time.
INSERT Department_History (DepartmentNumber, FOO) VALUES (4, 5), (6, 7), (8, 9);
  • I didnt get any error message.It work for me and last insert was succesful
    – KumarHarsh
    Dec 26, 2023 at 9:02

1 Answer 1


The error is not happening at parse time. It will succeed if you run Parse (Ctrl + F5) over your code selection.

Instead, the problem is in the Bind step.

I'll borrow this graph from Paul White's blog post Query Optimizer Deep Dive - Part 1

enter image description here

As for the question, I don't believe the SQL server (easily) surfaces in which step the error happened.

I've captured the error's call stack with Extended Events and then used SQLCallStackResolver to translate that

value   count
00 sqllang!XeSqlPkg::error_reported::Publish
01 sqllang!ErrorReportedAutoPublish::Publish
02 sqllang!CErrorReportingManager::CwchFormatAndPrint
03 sqllang!ex_vcallprint_no_dump
04 sqllang!SQLCompileHandler
05 SqlDK!CallExceptionHandler
06 SqlDK!ex_raise2
07 SqlDK!ex_raise_va_list
08 sqllang!alg_ex_raise
09 sqllang!CScaOp_Identifier::BindSelf
0a sqllang!CScaOpArg::BindScalarTree
0b sqllang!CScaOpArg::BindTree
0c sqllang!COptExpr::BindTree
0d sqllang!CRelOp_DML::BindColumnList
0e sqllang!CRelOp_Insert::GetLhsTypesForUnion
0f sqllang!CRelOp_Insert::BindTree
10 sqllang!COptExpr::BindTree
11 sqllang!CRelOp_DMLQuery::BindTree
12 sqllang!COptExpr::BindTree
13 sqllang!CRelOp_Query::FAlgebrizeQuery
14 sqllang!CProchdr::FNormQuery
15 sqllang!CProchdr::FNormalizeStep
16 sqllang!CSQLSource::FCompile
17 sqllang!CSQLSource::FCompWrapper
18 sqllang!CSQLSource::Transform
19 sqllang!CSQLSource::Compile
1a sqllang!CStmtPrepQuery::Init
1b sqllang!CCompPlan::FCompileStep
1c sqllang!CSQLSource::FCompile

You can see that just before the exception, it tried to BindTree.

  • Very helpful! Also, you might want to comment the call stack that you've given. The untrained eye has no idea what line(s) to look at or how/where they match the picture you've included.
    – J. Mini
    Dec 22, 2023 at 15:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.