Solved

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

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL trigger 5 32
SQL Query help 3 24
T-SQL Query - Group By Year 3 25
SP converting date time to date and time separately 2 12
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

685 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