SQL Statement that is determined by checkboxes

Posted on 2007-08-08
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.
Question by:PrimeNY
    1 Comment
    LVL 6

    Accepted Solution

    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 * 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

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    Format Number Field 10 34
    How to script out data export 36 54
    What are the big features of MVC5? 4 30
    Access Query concatenation 12 21
    PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
    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 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.…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…

    728 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

    19 Experts available now in Live!

    Get 1:1 Help Now