Mar 22, 2013

An expression of non-boolean type specified in a context where a condition is expected, near '' sql server


If we write non-boolean expression in IF statement, WHERE clause, HAVING clause etc it is comes under syntax error. For example:

DECLARE @Value AS BIT = 1

IF @Value
SELECT 1

Or

DECLARE @Parms AS INTEGER = 10
SELECT * FROM Student WHERE @Parms

If we will execute above queries will get error message:

An expression of non-boolean type specified in a context where a condition is expected, near ''.

Solution: We have to write valid Boolean expression. For example:

DECLARE @Value AS BIT = 1

IF @Value = 1
SELECT 1

Or

DECLARE @Parms AS INTEGER = 10
SELECT * FROM Student WHERE Roll_No > @Parms

1 comment:

  1. Anonymous1/14/2014

    Thanks this helped me today.

    ReplyDelete