Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old February 6th, 2007, 05:40 PM
Authorized User
 
Join Date: Mar 2005
Location: , , .
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Default And/Or Logic???

I create a report based on values passed from a front end. The user selects the statuses they want to see from checkboxes. The user can select a few different statuses.They can either select All, Pending, InReview, Cleared. If they select all I display all records. If they select cleared and pending I need to display only cleared and pending records.

These are the variables being passed:
@sStatusAll (0 If not selected, 1 if selected)
@sStatusPending (0 If not selected, 1 if selected)
@sStatusInReview (0 If not selected, 1 if selected)
@sStatusCleared (0 If not selected, 1 if selected)

In this case I would have to look at:
sStatusAll =0
sStatusPending =1
sStatusInReview =0
sStatusCleared =1

Based on these I need to produce the report to display only the pending and cleared records.

I am having trouble coming up with the query. Can anyone help?

Thanks,
Ninel


[code]
CREATE TABLE reCUSTOMER (
iID int IDENTITY (1, 1) NOT NULL ,
sCustName varchar(50) NULL,
sSIM varchar(20) NULL,
sPlanCode varchar(20) NULL,
iStatus int NULL)

INSERT reCUSTOMER (sCustName, sSIM, sPlanCode, iStatus )
VALUES('John Smith', '123', 'ABC', 'Pending')
INSERT reCUSTOMER (sCustName, sSIM, sPlanCode, iStatus )
VALUES('Jane Smith', '246', 'DEF', 'InReview')
INSERT reCUSTOMER (sCustName, sSIM, sPlanCode, iStatus )
VALUES('Joan Smith', '789', 'GHI', 'Cleared')
[code]

Reply With Quote
  #2 (permalink)  
Old February 9th, 2007, 11:30 AM
Authorized User
 
Join Date: Oct 2005
Location: , , .
Posts: 72
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I believe I answered the same question somewhere else. Here's the query:

SELECT * FROM reCustomer
WHERE @sStatusAll = 1 OR (@sStatusPending = 1 AND iStatus = 'Pending') OR
(@sStatusInReview = 1 AND iStatus = 'InReview') OR
(@sStatusCleared = 1 AND iStatus = 'Cleared')

SQL Server Helper
How well do you know SQL? Find out with the free test assessment from SQL Server Helper!!!
http://www.sql-server-helper.com/free-test/default.aspx

Got a SQL Server Question? Ask us here: http://www.sql-server-helper.com/forums/default.asp
Reply With Quote
  #3 (permalink)  
Old February 9th, 2007, 11:33 AM
Authorized User
 
Join Date: Mar 2005
Location: , , .
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you for your help. I really appreciate it.

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
help to solve the logic pradeepn XSLT 4 May 22nd, 2007 07:07 AM
RECURRING LOGIC its.shashank Classic ASP Databases 1 November 22nd, 2006 08:58 AM
Tricky logic (for me) cedwards Dreamweaver (all versions) 5 April 5th, 2006 05:47 PM
Mixing Data access logic and business logic polrtex BOOK: Professional Jakarta Struts 0 December 15th, 2003 07:19 PM



All times are GMT -4. The time now is 06:09 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.