avg_bloke
avg_bloke

Reputation: 214

SQL stored procedure return value on condition

I have to fetch data from [HospitalOwned] column when the value of the column has either yes or no as the value.

I'm calling a stored procedure and after passing the value of a variable @HospitalOwned='A' then the values must be fetched. I'm getting:

an expression of non-boolean type specified in context where a condition is expected error

  case when @HospitalOwned='A' then(([HospitalOwned] like '%yes%')or([HospitalOwned] like '%no%'))end

Upvotes: 0

Views: 728

Answers (1)

Giorgos Betsos
Giorgos Betsos

Reputation: 72165

You cannot use CASE this way in SQL. CASE is an expression that returns a scalar value, so it can't be used for controling execution flow like in procedural languages.

Consider using this predicate instead:

WHERE (@HospitalOwned <> 'A') OR
      (@HospitalOwned = 'A' AND (([HospitalOwned] like '%yes%') or ([HospitalOwned] like '%no%')))

Upvotes: 4

Related Questions