Click here to Skip to main content
15,887,477 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hello friend,

i make one storeprocedure for my search data but when i use this it fetch all data of my data base i want fecth male and female data

seprate here is my procedure

SQL
ALTER PROCEDURE Database.SelectQuickSearch

(
@Gender varchar(15),
@Age int,
@Height varchar(50),
@MartialStatus varchar(20),
@ReligionId int,
@CasteId int,
@Country varchar(50)

)

AS
    
    
    
    SELECT Registration.RegId, Registration.FirstName, Registration.LastName, Registration.Age, Registration.Gender, Registration.Height, Registration.Weight,
                  ReligionMaster.ReligionName, Registration.Country, CasteMaster.CasteName, Registration.Education
FROM     Registration INNER JOIN
                  ReligionMaster ON Registration.ReligionId = ReligionMaster.ReligionId INNER JOIN
                  CasteMaster ON Registration.CasteId = CasteMaster.CasteId
WHERE  (Registration.Gender = @Gender) OR
                  (Registration.Age = @Age) OR
                  (Registration.Height = @Height) OR
                  (Registration.MartialStatus = @MartialStatus) OR
                  (Registration.ReligionId = @ReligionId) OR
                  (Registration.CasteId = @CasteId) OR
                  (Registration.Country = @Country)
Posted
Updated 26-Jul-12 20:35pm
v2

Try this:
SQL
--Use AND instead of OR
ALTER PROCEDURE Database.SelectQuickSearch
(
@Gender varchar(15),
@Age int,
@Height varchar(50),
@MartialStatus varchar(20),
@ReligionId int,
@CasteId int,
@Country varchar(50) 
)
 
AS
SELECT Registration.RegId
	 , Registration.FirstName
	 , Registration.LastName
	 , Registration.Age
	 , Registration.Gender
	 , Registration.Height
	 , Registration.Weight
	 , ReligionMaster.ReligionName
	 , Registration.Country
	 , CasteMaster.CasteName
	 , Registration.Education
FROM
	Registration
	INNER JOIN
		ReligionMaster
		ON Registration.ReligionId = ReligionMaster.ReligionId
	INNER JOIN
		CasteMaster
		ON Registration.CasteId = CasteMaster.CasteId
WHERE
	(Registration.Gender = @Gender)
	AND
	(Registration.Age = @Age)
	AND
	(Registration.Height = @Height)
	AND
	(Registration.MartialStatus = @MartialStatus)
	AND
	(Registration.ReligionId = @ReligionId)
	AND
	(Registration.CasteId = @CasteId)
	AND
	(Registration.Country = @Country)
 
Share this answer
 
Comments
shinebudy 27-Jul-12 2:46am    
not worked
Prasad_Kulkarni 27-Jul-12 2:47am    
What you are passing in @Gender parameter.
shinebudy 27-Jul-12 2:50am    
passing through gender
shinebudy 27-Jul-12 2:51am    
sorry through session
Prasad_Kulkarni 27-Jul-12 2:52am    
so you get male or female there itself then what is the problem?
hi,

There are lots of OR conditions in
SQL
WHERE
clause, which means if any of the condition is true, it will fetch all the data..
Use
SQL
AND
instead of
SQL
OR
.


Also, if you will use
SQL
AND
, make sure that whether relevant data is present in DB or not.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900