Solved

SQL query to decode a value returned from function

Posted on 2008-06-18
3
708 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 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 200 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 50 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now