Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2008-06-19
2
Medium Priority
?
170 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
[X]
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
2 Comments
 
LVL 2

Accepted Solution

by:
AntonyDN earned 1000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

636 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