// SQL Server error reference

SQL Server error 4145: Non-boolean expression in a condition

WHERE, HAVING, IF, WHILE, ON or CASE WHEN got a value instead of a true/false condition, such as WHERE IsActive instead of WHERE IsActive = 1.

Error number
4145
Severity
15
Category
Syntax and compilation
Error message
An expression of non-boolean type specified in a context where a condition is expected, near '%.*ls'.

What it means

T-SQL has no boolean column type that can stand alone as a condition. Clauses that need a predicate (WHERE, ON, HAVING, IF, WHILE, CASE WHEN) require a comparison or an expression such as EXISTS, IN or LIKE. A bare column, variable or function result fails with 4145.

Common causes

  • Treating a bit column as a boolean: WHERE IsActive (valid in PostgreSQL and MySQL, not in T-SQL).
  • A missing comparison operator, or a typo that turns a comparison into a value.
  • Calling a scalar function that returns bit without comparing its result.

How to fix it

  1. Compare explicitly.

    SELECT * FROM dbo.Users WHERE IsActive = 1;
    IF dbo.IsWeekend(@d) = 1 PRINT 'weekend';
  2. For dynamic conditions, build the full predicate, not just the column name.

Reproduce it safely

DECLARE @flag bit = 1;
IF @flag PRINT 'yes';  -- Msg 4145

Related errors

More syntax and compilation errors

The code and message text are from the Microsoft Database Engine events and errors reference. Browse the full SQL Server error list or search every database error.

// fewer errors, faster fixes

Work on SQL Server in SQLly

A native SQL client for macOS, Windows and Linux with schema-aware IntelliSense, guardrails for risky statements and clear error messages, for SQL Server and the other databases you use.