Hi All,
I am working on a Windows Form Application where I need to use below StoredProcedure for search voter list.
I have below StoredProcedure
USE [VMS]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[GetVotersList]
@language nvarchar(255),
@firstName nvarchar(255),
@middleName nvarchar(255),
@lastNAme nvarchar(255),
@SrNo int,
@sex nvarchar(10),
@minAge int,
@maxAge int,
@vCardId nvarchar(50),
@address nvarchar(255),
@yadiNo nvarchar(255),
@mLanguage nvarchar(50),
@Religion nvarchar(50),
@Caste nvarchar(50)
as
begin
if(@language = 'English')
begin
if(@sex = 'A')
begin
Select SrNo as 'Serial #', eLastName + ' '+ eFirstName + ' '+ eMiddleName as 'Name', sex, age,
VCardId, GharNo, eAddress as 'Address', YadiNo, mobileNo as 'Mobile No',
from Voter
where eFirstName like @firstName+'%' and emiddleName like @middleName+'%' and
eLastName like @lastName+ '%' and age > @minAge and age < @maxAge and
VCardId like @vCardId +'%' and eAddress like '%'+@address+'%' and yadiNo like @yadiNo +'%'
select count(*) from Voter
where eFirstName like @firstName+'%' and emiddleName like @middleName+'%' and
eLastName like @lastName+ '%' and age > @minAge and age < @maxAge and
VCardId like @vCardId +'%' and eAddress like '%'+@address+'%' and yadiNo like @yadiNo +'%'
and sex='M'
end
else
begin
Select SrNo as 'Serial #', eLastName + ' '+ eFirstName + ' '+ eMiddleName as 'Name', sex,
age, VCardId, GharNo, eAddress as 'Address', YadiNo, mobileNo as 'Mobile No',
emailId as 'Email Id'
from Voter
where eFirstName like @firstName+'%' and emiddleName like @middleName+'%' and
eLastName like @lastName+ '%' and age > @minAge and age < @maxAge and sex = @sex and
VCardId like @vCardId +'%' and eAddress like '%'+@address+'%' and yadiNo like @yadiNo +'%'
select count(*) from Voter
where eFirstName like @firstName+'%' and emiddleName like @middleName+'%' and
eLastName like @lastName+ '%' and age > @minAge and age < @maxAge and sex = @sex and
VCardId like @vCardId +'%' and eAddress like '%'+@address+'%' and yadiNo like @yadiNo +'%'
and sex='M'
end
end
else
begin
if(@sex = 'A')
begin
Select SrNo as 'Serial #', mLastName + ' '+ mFirstName + ' '+ mMiddleName as 'Name', sex,
age, VCardId, GharNo, mAddress as 'Address', YadiNo, mobileNo as 'Mobile No',
emailId as 'Email Id'
from Voter
where eFirstName like @firstName+'%' and emiddleName like @middleName+'%' and
eLastName like @lastName+ '%' and age > @minAge and age < @maxAge and
VCardId like @vCardId +'%' and eAddress like '%'+@address+'%' and yadiNo like @yadiNo +'%'
select count(*) from Voter
where eFirstName like @firstName+'%' and emiddleName like @middleName+'%' and
eLastName like @lastName+ '%' and age > @minAge and age < @maxAge and
VCardId like @vCardId +'%' and eAddress like '%'+@address+'%' and yadiNo like @yadiNo +'%'
and sex='M'
end
else
begin
Select SrNo as 'Serial #', mLastName + ' '+ mFirstName + ' '+ mMiddleName as 'Name', sex, age, VCardId, GharNo, mAddress as 'Address', YadiNo, mobileNo as 'Mobile No', emailId as 'Email Id' from Voter
where eFirstName like @firstName+'%' and emiddleName like @middleName+'%' and
eLastName like @lastName+ '%' and age > @minAge and age < @maxAge and sex = @sex and
VCardId like @vCardId +'%' and eAddress like '%'+@address+'%' and yadiNo like @yadiNo +'%'
and sex='M'
select count(*) from Voter
where eFirstName like @firstName+'%' and emiddleName like @middleName+'%' and
eLastName like @lastName+ '%' and age > @minAge and age < @maxAge and sex = @sex and
VCardId like @vCardId +'%' and eAddress like '%'+@address+'%' and yadiNo like @yadiNo +'%'
and sex='M'
end
end
end
this works fine (gives me list of voter exactly match the search query like sure name, first name etc.)but when I add some more functionality to it gives wrong output. Additional functionality code is below
Firstly I am searching for below values only
@language nvarchar(255),
@firstName nvarchar(255),
@middleName nvarchar(255),
@lastNAme nvarchar(255),
@SrNo int,
@sex nvarchar(10),
@minAge int,
@maxAge int,
@vCardId nvarchar(50),
@address nvarchar(255),
@yadiNo nvarchar(255),
and now I want to add three more values to search they are
@mLanguage nvarchar(50),
@Religion nvarchar(50),
@Caste nvarchar(50)
I have coded as values coded earlier but it gives me only first 2 rows only.
Please advise me what's wrong here.
Sorry for incomplete info. Hope it's little bit clear now.
Thanks in advance.