Solved

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

Posted on 2008-06-19
2
162 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
Comment Utility
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
Comment Utility
Thanks for your help
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
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.
This video discusses moving either the default database or any database to a new volume.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

771 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

10 Experts available now in Live!

Get 1:1 Help Now