Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Need to build a three way query based on a value in radio button

Posted on 2008-06-19
2
165 Views
Last Modified: 2010-05-18
I had asked a question earlier and here is the link
http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SQL-Server-2005/Q_23496475.html

since then the requirements have changed
The user wants the capability to select All Orders, Only Valid Orders , or Exclude Invalid Orders.
Valid values for the parameter @Check = 'true', 'false' or 'all', for which I have added a radio button on the screen instead of a checkbox that I had earlier.

Default value of @Check = 'all'.
The function fn_CheckValid accepts an input of string and returns 0 or 1, based on whether the order is valid or invalid

My current AND condition in the select clause handles only the true or false condition
select .....
And (@Check = 0 or (fn_CheckValid(strOrder) = @Check))

0
Comment
Question by:countrymeister
2 Comments
 
LVL 2

Accepted Solution

by:
AntonyDN earned 250 total points
ID: 21823647
I think you have got your data type for @Check muddled; is it a BIT or a string type? You might need to do some type conversions

You only seem to have two options here. "All Orders" (ie Valid and Invalid), or "Valid Only".
Your third option of exclude invalid is surely the same as "Valid Only"

Anyway, the logic you need is '
WHERE colA = Colb
.....
AND (
      (@Check = 'all')
OR
      (@Check IN ('True', 'False')
      AND (fn_CheckValid(strOrder) = @Check))
      )
      -- Looking at your previous post, this is probably how you should code the line above
      AND (select case when dbo.fn_CheckValid(strOrder)  = 1 THEN 'True' Else 'False' end )  = @Check))

That way, if @Check = 'all' then you won't call the function.
0
 
LVL 1

Author Closing Comment

by:countrymeister
ID: 31468763
Thanks for your help
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

808 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