?
Solved

SQL Statement that is determined by checkboxes

Posted on 2007-08-08
1
Medium Priority
?
200 Views
Last Modified: 2013-11-27
I'm building a web site using Visual Web Developer 2005 Express.  I have a data control that dispays properties for sale.  I use the following sql statement:  

SELECT * FROM [BusDescription]

I've added three checkboxes (ckbNY, ckbNJ, ckbCT) to the page and I want the user to be able to limit the properties for that he/she sees to the ones that he/she has left checked.  In another words, if he/she doesn't want to see properties in CT then he/she would un-check the ckbCT.  (checkbox default is checked)

What does the sql statement look like to make this happen?

Thanks in advance.
0
Comment
Question by:PrimeNY
1 Comment
 
LVL 6

Accepted Solution

by:
itdrms earned 2000 total points
ID: 19654846
Assuming you are passing the state of each checkbox into SQL, you can use a CASE statement

Example to demonstrate:
DECLARE @ChkNY bit, @ChkNJ bit, @ChkCT bit
SET @ChkNY = 1
SET @ChkNJ = 1
SET @ChkCT = 0

DECLARE @BusDescription TABLE (ID int identity(1,1),PropState char(2))
INSERT INTO @BusDescription
SELECT 'NY'
UNION ALL SELECT 'NY'
UNION ALL SELECT 'NJ'
UNION ALL SELECT 'NJ'
UNION ALL SELECT 'NJ'
UNION ALL SELECT 'CT'

SELECT * FROM @BusDescription
WHERE CASE @ChkNY WHEN 1 THEN 'NY' END = PropState
OR  CASE @ChkNJ WHEN 1 THEN 'NJ' END = PropState
OR  CASE @ChkCT WHEN 1 THEN 'CT' END = PropState
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying 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

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
Article by: Tammy
MySQLTuner is a script written in Perl that allows you to review a MySQL installation quickly and make adjustments to increase performance and stability. The current configuration variables and status data is retrieved and presented in a brief forma…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
SQL Database Recovery Software repairs the MDF & NDF Files, corrupted due to hardware related issues or software related errors. Provides preview of recovered database objects and allows saving in either MSSQL, CSV, HTML or XLS format. Ensures recov…

621 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