SQL query to decode a value returned from function

I have a stored procedure which has a few parameters.
One of the parameters is @Check

I need to decode a value returned from a function
fn_CheckValid which takes in a string of an order no and returns 0 or 1

what I need to do is if the value returned is 0 - interpret as false if 1 interpret as true
and then check this with @Check parameter. @Check can have only two vlaue true or false

So I need somehow to convert the value returned from the function to true or false and then check if it matches the parameter @Check

This is what I have now, but is incorrect since the value returned from function is fn_CheckValid is only 1 or 0 and the @check is only true or false.

fn_CheckValid(strOrder) = @Check
Who is Participating?
Guy Hengel [angelIII / a3]Connect With a Mentor Billing EngineerCommented:
what data type is @check ? assuming that it is "bit" data type, that code will do.
Aneesh RetnakaranConnect With a Mentor Database AdministratorCommented:
if (select case when dbo.fn_CheckValid(strOrder)  = 1 THEN 'True' Else 'False' end )  = @Check
countrymeisterAuthor Commented:
Angel, I had @Check as string, I made that a bit and it worked.

Aneesh , your solution worked too, but I was looking for minimal change on the code I had
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.