select reg.RegID,reg.FName+' '+reg.MName+' '+reg.Surname as PatientName,reg.MName+' '+reg.Surname as PtName,reg.PAddress,
CONVERT(char(10),reg.BDate,103)as BDate,(DATEDIFF(YEAR, reg.BDate, GETDATE())) AS Age,
case when CONVERT(char(10),reg.MarriageDate,103)='01/01/1900' then '-' else
(DATEDIFF(YEAR, reg.MarriageDate, GETDATE())) end as MrgYear ,
CONVERT(char(10),reg.MarriageDate,103)as MarriageDate,reg.Religion,reg.BloodGroup,
reg.HeighttFt,reg.HeightInc,reg.PWeight,
reg.Mobile,reg.Mail,reg.Gender,reg.Occupation,reg.RegistrationFor,
logi.Password,CONVERT(char(10),reg.EntryDate,103) as EntryDate,ad.Name as CityName
from RegistrationMst reg left outer join LoginMst logi on (reg.RegID=logi.UserID)
inner join AddressMst ad on (reg.CityID=ad.SrNo)
where reg.IsActive=1
and (reg.RegID=@RegID or @RegID=-1)
and (reg.Mobile like '%'+ @Mobile +'%' or @Mobile='')
and ((CONVERT(char(10),reg.EntryDate,103) between (CONVERT(char(10),@FromDate,103)) and CONVERT(char(10),@ToDate,103)) or
(CONVERT(char(10),@FromDate,103)='01/01/1900' and CONVERT(char(10),@ToDate,103)='01/01/1900'))