if @gender='male'
begin
set @gender='female'
begin
select top 8 p.Reg_id,dbo.getage(DateofBirth,GETDATE()) as age,r.Height,p.Religion,p.Caste,r.District from dbo.matrimony_Personaldetails as p left outer join dbo.matrimony_register as r on r.Reg_id=p.Reg_id where Religion=@religion and Gender=@gender and Height<=@Height and DateofBirth>=@dob
end
else
begin
set @gender='male'
if @caste='any'
begin
select top 8 p.Reg_id,dbo.getage(DateofBirth,GETDATE()) as age,r.Height,p.Religion,p.Caste,r.District from dbo.matrimony_Personaldetails as p left outer join dbo.matrimony_register as r on r.Reg_id=p.Reg_id where Religion=@religion and Gender=@gender and Height>=@Height and DateofBirth<=@dob
end