[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.6

How to search in a table based on multiple criteria

Asked by bkerson in MS SQL DTS, SQL Query Syntax, SQL Server 2005

Tags: SQL

Hello

I would like to search in a table based on 6 different fields. I need the user to be able to enter 1 or 2 criteria or even 3,4...6 criteria and they should get the result.

Field critera:  

LastName nchar(50),
FirstName nchar(50),
School_Name char(50),
Organization char(70),
Home_Phone char(24),
Transportation_Type char(50)

Note: user can type any character in the field and the query should look for in the database and return something. Example: If there is a LastName named Joseph. As soon the user type the first 3 character or even 1 character in just  the lastname field. The query should should take care of the rest of character

I wrote the code below but my problem is : user needs to fill all 6 fields in order to get a result otherwise user gets an asp.net error message in the page

Any help will be greatly apreciated

Thanks


1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
create PROCEDURE [dbo].[usp_Search]
	-- Add the parameters for the stored procedure here
			@LastName nchar(50),
            @FirstName nchar(50),
			@School_Name char(50),
			@Organization char(70),
			@Home_Phone char(24),
			@Transportation_Type char(50)
AS
BEGIN
	-- Declare the variables.
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
	BEGIN
		
	SELECT 
	  [Student_ID],
	  [LastName],
      [MiddleName],
      [FirstName],
      [Birthdate],
      [Sex],
      [Home_Phone],
      [Cell_Phone],
      [Parent],
      [STU_Address],
      [City],
      [Country_State],
      [Zip_Code],
      [School_Year],
      [School_Name],
      [Organization],
      [Transportation_Type]
	   FROM [LABBB].[dbo].[MasterStudent]
		WHERE	LastName LIKE CASE WHEN @LastName IS NULL THEN '%' ELSE '%' + @LastName + '%' END
				AND FirstName LIKE CASE WHEN @FirstName IS NULL THEN '%' ELSE '%' + @FirstName + '%' END
				AND School_Name LIKE CASE WHEN @School_Name IS NULL THEN '%' ELSE '%' + @School_Name + '%' END
				AND Organization LIKE CASE WHEN @Organization IS NULL THEN '%' ELSE '%' + @Organization + '%' END
				AND Home_Phone LIKE CASE WHEN @Home_Phone IS NULL THEN '%' ELSE '%' + @Home_Phone + '%' END
				AND Transportation_Type LIKE CASE WHEN @Transportation_Type IS NULL THEN '%' ELSE '%' + @Transportation_Type + '%' END
	END
[+][-]10/29/09 12:01 PM, ID: 25697009Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: MS SQL DTS, SQL Query Syntax, SQL Server 2005
Tags: SQL
Sign Up Now!
Solution Provided By: MuhammadKashif
Participating Experts: 1
Solution Grade: B
 
[+][-]10/29/09 12:42 PM, ID: 25697458Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/29/09 01:14 PM, ID: 25697777Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-89 - Hierarchy / EE_QW_3_20080625