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

x
?
Solved

sql server 2008 query

Posted on 2013-06-26
1
Medium Priority
?
447 Views
Last Modified: 2013-06-26
I'm using Sql server 2008.
This example uses the Employees table from the Northwind database.
I have a asp.net page where I have a RadioButtonList.

The RadioButtonList has 3 possible selections.

One is called Query 1 which will have a value of 1
the other is called Query 2 which will have a value of 2
and the other is called Query 3 which will have a value of 3



How would I write a query to handle the following:

If the Query 1 radio button is selected run this query

SELECT [EmployeeID],[LastName],[FirstName],[Title],[TitleOfCourtesy],[BirthDate],[HireDate],[Address],[City],[PostalCode],[Country],[HomePhone]
FROM [Northwind].[dbo].[Employees] WHERE [EmployeeID] < 4
 

If the Query 2  radio button is selected run this query

SELECT [EmployeeID],[LastName],[FirstName],[Title],[TitleOfCourtesy],[BirthDate],[HireDate],[Address],[City],[PostalCode],[Country],[HomePhone]
FROM [Northwind].[dbo].[Employees] WHERE [EmployeeID] > 4


If the Query 3  radio button is selected run this query

SELECT [EmployeeID],[LastName],[FirstName],[Title],[TitleOfCourtesy],[BirthDate],[HireDate],[Address],[City],[PostalCode],[Country],[HomePhone]
FROM [Northwind].[dbo].[Employees] WHERE [EmployeeID] = 6

Can I just use a case statement?

This query is going to go inside a stored procedure that I am just going to pass in the parameter selected from the radion button to the stored procedure.

So the stored procedure will only run one of these queries depending on what parameter I passed it.
So if I passed it a value of 1 then query 1 should run
     if I passed it a value of 2 then query 2 should run
     if I passed it a value of 3 then query 3 should run

Any ideas?

Thanks.
0
Comment
Question by:maqskywalker
[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
1 Comment
 
LVL 21

Accepted Solution

by:
Dale Burrell earned 2000 total points
ID: 39280026
The following should do that I think, I've written for testing, you just change the var to be the SP parameter.

declare @InputValue int

set @InputValue = 1

SELECT [EmployeeID],[LastName],[FirstName],[Title],[TitleOfCourtesy],[BirthDate],[HireDate],[Address],[City],[PostalCode],[Country],[HomePhone]
FROM [Northwind].[dbo].[Employees]
WHERE (@InputValue = 1 and [EmployeeID] < 4)
or (@InputValue = 2 and [EmployeeID] > 4)
or (@InputValue = 3 and [EmployeeID] = 6)

Open in new window

0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

604 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