Advertisement

10.28.2007 at 07:45PM PDT, ID: 22923597
[x]
Attachment Details

Help with the SQL View

Asked by TECH_NET in SQL Server 2005, MS SQL Server

Tags: sql, view

I have written the following procedure which is used to query a VIEW based on the Input parameters. If any one of the input parameter passed to this procedure is -1, then i do not want that corresponding column in the Where clause to be executed. (ie if @Weight is -1 then in the where clause WEIGHT column should not be used to filter the search results.

I have one record with the country set as 252 (ie USA) and when that is the only input parameter passed with a value other than -1, i should be seeing the record, but i do not see the same. Can anyone help me find an issue with the procedure i have written and if there is a better way to implement, please do let me know.

Also one another question, i want to Use the @AGE1, @AGE2 , to compare if the value Column  AGE lies between @AGE1 and @AGE2 and if so those records should be retrieved . Just add this criteria to the current procedure.


PROCEDURE [dbo].[DRM_ProfileSearch_RetrieveProfiles]
(
@AGE1_ID int,
@AGE2_ID int,
@HEIGHT_ID int,
@WEIGHT_ID int,
@RELIGION_ID int,
@GENDER_ID int,
@CASTE_ID int,
@MARITIAL_STATUS_ID int,
@EDUCATION_ID int,
@STATE_ID int,
@COUNTRY_ID int,
@PROFESSION_ID int,
@CITIZENSHIP_ID int,
@IS_PHOTO_ID int,
@SEEKING_ID int,
@SEARCH_QUERY nvarchar(1000)
)
AS

SET NOCOUNT OFF;
 
 IF @AGE1_ID = -1   SET @AGE1_ID = NULL
IF @AGE2_ID = -1   SET @AGE2_ID = NULL
IF @HEIGHT_ID = -1   SET @HEIGHT_ID = NULL
IF @WEIGHT_ID = -1     SET @WEIGHT_ID = NULL
IF @RELIGION_ID = -1     SET @RELIGION_ID = NULL
IF @GENDER_ID = -1   SET @GENDER_ID = NULL
IF @CASTE_ID = -1   SET @CASTE_ID = NULL
IF @MARITIAL_STATUS_ID = -1 SET @MARITIAL_STATUS_ID = NULL
IF @EDUCATION_ID = -1 SET @EDUCATION_ID = NULL
IF @STATE_ID = -1 SET @STATE_ID = NULL
IF @COUNTRY_ID = -1 SET @COUNTRY_ID = NULL
IF @PROFESSION_ID = -1 SET @PROFESSION_ID = NULL
IF @CITIZENSHIP_ID = -1 SET @CITIZENSHIP_ID = NULL
IF @IS_PHOTO_ID = -1 SET @IS_PHOTO_ID = NULL
IF @SEEKING_ID = -1 SET @SEEKING_ID = NULL
IF @SEARCH_QUERY = '' SET @SEARCH_QUERY = NULL

SELECT  * FROM DRM_PERSONALS_M_VIEW
WHERE  
(@HEIGHT_ID IS NULL OR @HEIGHT_ID = HEIGHT_ID) AND
(@WEIGHT_ID IS NULL OR @WEIGHT_ID =  WEIGHT_ID) AND
(@RELIGION_ID IS NULL OR @RELIGION_ID =  RELIGION_ID) AND
(@GENDER_ID IS NULL OR @GENDER_ID =  GENDER_ID) AND
(@CASTE_ID IS NULL OR @CASTE_ID =  CASTE_ID) AND
(@MARITIAL_STATUS_ID IS NULL OR @MARITIAL_STATUS_ID =  MARITIAL_STATUS_ID) AND
(@EDUCATION_ID IS NULL OR @EDUCATION_ID =   EDUCATION_ID) AND
(@STATE_ID IS NULL OR @STATE_ID =   STATE_ID) AND
(@COUNTRY_ID IS NULL OR @COUNTRY_ID =   COUNTRY_ID) AND
(@PROFESSION_ID IS NULL OR @PROFESSION_ID =   PROFESSION_ID) AND
(@CITIZENSHIP_ID IS NULL OR @CITIZENSHIP_ID =   CITIZENSHIP_ID) AND
(@IS_PHOTO_ID IS NULL OR @IS_PHOTO_ID =   IS_PHOTO_ID) AND
(@SEEKING_ID IS NULL OR @SEEKING_ID =    SEEKING_ID)

ORDER BY PROFILE_ID



Start Free Trial
[+][-]10.28.2007 at 07:59PM PDT, ID: 20167384

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 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.28.2007 at 08:03PM PDT, ID: 20167402

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 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.28.2007 at 08:07PM PDT, ID: 20167424

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 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.28.2007 at 08:15PM PDT, ID: 20167468

View this solution now by starting your 7-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: SQL Server 2005, MS SQL Server
Tags: sql, view
Sign Up Now!
Solution Provided By: TECH_NET
Participating Experts: 2
Solution Grade: A
 
 
[+][-]10.28.2007 at 08:27PM PDT, ID: 20167496

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 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.28.2007 at 10:39PM PDT, ID: 20167745

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 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.29.2007 at 06:52AM PDT, ID: 20169377

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 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.29.2007 at 08:55AM PDT, ID: 20170528

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 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.29.2007 at 09:32AM PDT, ID: 20170896

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 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.29.2007 at 09:41AM PDT, ID: 20170976

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 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.29.2007 at 09:44AM PDT, ID: 20171009

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 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.29.2007 at 09:53AM PDT, ID: 20171090

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 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.29.2007 at 10:09AM PDT, ID: 20171229

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 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628