parthiban karnan

parthiban karnan

  • NA
  • 549
  • 101.6k

HOW TO CODE FOR THE THIS STOREDPROCEDURE

May 27 2013 6:45 AM
I GOT A STORED PROCEDURE FOR RETRIEVING DATA FROM FILTERED SEARCH.. A DROPDOWN WITH FIRSTNAME,LASTNAME AND  EMAIL AND A TEXTBOX WHICH FILTERS WITH EXACT SEARCH..

BELOW IS SP.. HOW TO CODE FOR THIS...

IF I CHOOSE FIRTSNAME FROM DDL AND ENTER FIRSTNAME IN TEXTBOX.. IT HAS TO FILTER AND BIND WITH EXACT DETAILS IN GRIDVIEW...SAME AS  FOR LASTNAME AND EMAIL...


Create Procedure [dbo].[spSearch]
@firstName nvarchar(50) = null,
@lastName nvarchar(50) = null,
@email nvarchar(50) = null
AS 
BEGIN

If @firstName is not null and Len(@firstName )=0 Set @firstName = null
If @lastName is not null and Len(@lastName )=0 Set @lastName = null
If @email is not null and Len(@email )=0 Set @email = null

Select 
*
From userinf
Where 
( @firstName is null or firstName Like @firstName )
and ( @lastName is null or lastName Like @lastName )
and ( @email is null or email Like @email )
END 

GO


 

Answers (5)