Abhimanyu Singh

Abhimanyu Singh

  • NA
  • 116
  • 48k

check this "Where condition" for multiple column Search

Sep 20 2013 4:55 AM
Hello All here,

Please check the "where condition" in below mentioned Store procedure for fetching multiple column data on button click.

Actually i want that..search data should come on..when we are selecting Dropdown list first then/or email_id selection in text box...means we can select both together or seperatly..then serchin data should display in gridview on button click function..Please help me

Because its working only for dropdownlist selection not for email_id together or seperate selection

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
Select 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,
       U.StateId,
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
Where U.UserType IS NOT NULL AND (U.UserType=@UserType And U.ActiveFlag=1)or(U.UserType=@UserType And U.EmailId=@EmailId And U.ActiveFlag=1)
--Where (U.UserType=@UserType And U.ActiveFlag=1)And(U.EmailId=@EmailId And U.ActiveFlag=1)
END TRY
BEGIN CATCH
SET @SqlMsg=ERROR_MESSAGE()
END CATCH

END

Answers (2)