Solved

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

Posted on 2008-06-19
2
164 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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Creating and Managing Databases with phpMyAdmin in cPanel.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
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…

773 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