?
Solved

SQL query to decode a value returned from function

Posted on 2008-06-18
3
Medium Priority
?
720 Views
Last Modified: 2010-04-21
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
0
Comment
Question by:countrymeister
3 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 800 total points
ID: 21816051
what data type is @check ? assuming that it is "bit" data type, that code will do.
0
 
LVL 75

Assisted Solution

by:Aneesh Retnakaran
Aneesh Retnakaran earned 200 total points
ID: 21816054
if (select case when dbo.fn_CheckValid(strOrder)  = 1 THEN 'True' Else 'False' end )  = @Check
0
 
LVL 1

Author Closing Comment

by:countrymeister
ID: 31468528
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
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
MSSQL DB-maintenance also needs implementation of multiple activities. However, unprecedented errors can hamper the database management. In that case, deploying Stellar SQL Database Toolkit ensures fast and accurate database and backup repair as wel…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question