I am writing store procedure for searching by UserType,EmailId and by First name from tblUser
I written the following code but i am not getting aspected result please check the where clause and also inner join because when i am changing the where clause conditions its giving result but throwing sql msg==>StateName property is not found i did not get it please check both.
ALTER Procedure [dbo].[Usp_SearchUserDetails]
(
@UserId int=NULL,
@UserType nvarchar(50)=NULL,
@FirstName nvarchar(50)=NULL,
@EmailId nvarchar(50)=NULL,
@StateId nvarchar(10)=NULL,
@DistrictId nvarchar(10)=NULL,
@SqlMsg nvarchar(Max)output
)
As
BEGIN
SET @SqlMsg=''
DECLARE @strQuery nvarchar(max)
BEGIN TRY
SET @strQuery='ROW_NUMBER()Over(Order By U.AddDate Desc) as SerialNo,
U.UserType,
U.EmailId,
U.FirstName,
U.LastName,
U.PhoneNo,
U.MobileNo,
U.[Address],
U.PinCode,
U.Company,
S.StateName,
D.DistrictName,
[Password],
CONVERT(Varchar,U.AddDate,103) as AddDate
from tblUser as U
inner join tblState as S
On U.StateId=S.StateId
Inner Join tblDistrict as D
on U.DistrictId=D.DistrictId
Order by U.AddDate Desc
Where UserType=@UserType And EmailId=@EmailId'
IF(@StateId !='0' And @StateId IS Not Null)
Begin
SET @strQuery= @strQuery +' and U.StateId = '''+ @StateId +''' '
End
IF(@DistrictId != '0' And @DistrictId IS Not Null)
Begin
SET @strQuery=@strQuery + ' and U.DistrictId = ''' +@DistrictId+''' '
End
Begin
SET @strQuery=@strQuery + ' Order By U.UserId Desc'
end
print (@strQuery)
Exec(@strQuery)
END TRY
BEGIN CATCH
SET @SqlMsg=ERROR_MESSAGE()
END CATCH
END

Iftikar HussainPosted Aug 16, 2013, 5:12 AM
Regards,
Iftikar
Iftikar HussainPosted Aug 16, 2013, 10:23 AM
Can you debug and check
Regards,
Iftikar
Abhimanyu SinghPosted Aug 16, 2013, 7:07 AM
Its working almost with searching keywords Email_Id or with First Name Also but...Check the Where condition below...because While i am selecting UserType in Dropdown list its showing
Empty Grid.."No Record found" this is first keywords after this as i selected EmailId and clicked on Search button Its showing result now.
Abhimanyu SinghPosted Aug 16, 2013, 5:07 AM
tblState:
tblUser:
Rest thing(Search procedure) mentioned in asked question above....
Iftikar HussainPosted Aug 14, 2013, 7:40 AM
Is StateName is exist in tblState? Can you check?
If possible provide all there table schema.
Regards,
Iftikar
Abhimanyu SinghPosted Aug 14, 2013, 7:36 AM
No, Actually Before applying of inner join code it was searching/Fetching some but it was showing Sql query msg==> StateName Property is not found so, then applied the above inner join code with help of goooled....but now its not working showing record not found please check the where condition because it wsa same befor apply the inner join code..may be it need to change...and i dont have concept of join..Please Help
Posted Aug 14, 2013, 7:20 AM
I hope the districts are associated with state table.
and S.StateId = D.StateId