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
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
bitcolumn 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
bitwithout comparing its result.
How to fix it
-
Compare explicitly.
SELECT * FROM dbo.Users WHERE IsActive = 1; IF dbo.IsWeekend(@d) = 1 PRINT 'weekend';
-
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
102Incorrect syntax near42804PostgreSQL: datatype mismatch1064MySQL: You have an error in your SQL syntax
More syntax and compilation errors
156Incorrect syntax near the keyword105Unclosed quotation mark after the string8120Column not in GROUP BY or aggregate8118Aggregate without GROUP BY8672MERGE touched the same row twice1934SET options have incorrect settings
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.
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.