Solved

SQL query to decode a value returned from function

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Suggested Solutions

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

864 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

24 Experts available now in Live!

Get 1:1 Help Now