below my stored procedure display all duplicate values ......plz write storedprocedure quarie display only distinct names..
storedprocedure....
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER Proc [dbo].[Register_List]
(
@flag int=null,
@srch varchar(max)=null
)
as
begin
if(@flag=1)
begin
select R.SNO,
R.IdNo,
R.SurName,
R.MiddleName,
R.LastName,
R.FatherName,
CONVERT(nvarchar,R.DOB,106)as DOBs,
R.Sex,
R.DNO,
R.Street,
R.Colony,
R.Location,
Mc.MasterName as City,
Md.MasterName as District,
R.Pin,
R.LandLine,
R.Mobile,
R.Email,
R.Qualification,
R.Occupation,
R.Voter,
R.Locality,
R.StationNo,
R.VoterIdNo,
R.VoterSerailNo,
R.ReferMemberId,
R.ReferSurName,
R.ReferMiddleName,
R.ReferLastName,
M.MasterName as Category ,
M.MasterName as ReferType,
R.Localityinterest,
CONVERT(nvarchar,R.CreatedOn,106)as crt,
CONVERT(nvarchar,R.Marriage_Date,106)as Marriage_Date,
R.Division
from Registration R
left join tblMaster M on(R.Category=M.MasterId)
left join tblMaster Mc on(R.City=Mc.MasterId)
left join tblMaster Md on(R.District=Md.MasterId)
where MiddleName like + '%' + @srch +'%'
end
Loading
Arul ManivannanPosted Mar 19, 2013, 4:59 AM
Use DISTINCT in select query.
Eg: Select DISTINCT R.IdNo,
R.SurName,
R.MiddleName,
R.LastName,
R.FatherName.........................
DISTINCT is bit risky and this may be the temporary solution. For the proper usage, you must
1. not allow duplicate records inside the table
2. Check your left join statement as you may missed to include matching columns.
- Arul Manivannan