I have a sample query like this:
select t1.name,t1.bday,t2.address,t2.contactnum
from table1 as t1
left join table2 as t2 on t1.p_id = t2.p_id
where (case when @qualified = '2' then t2.role is null
case when @qualified = '3' then t2.role is not null` end)
When I execute the query an error pops up indicating:
Incorrect syntax near the keyword 'is'.
Any idea for a work around for this guys?
Thanks!
The purpose of this query is to get the null rows in the table and the non-null rows depending on the value passed on parameter @qualified.
case when? You placedis nullandis not nullincorrectly in your query.CASEin T-SQL can only return a single, atomic value - not an expression / code block.