Hi Mahesh1986,
As per your query i have create the sample. If you have any doubt please revert me back. Below is the given sample.
SQL
CREATE PROCEDURE Employee_GetDetailsBasedonGender
@Gender VARCHAR(10) = NULL
AS
BEGIN
DECLARE @Employee TABLE
(
Eid INT
,Name VARCHAR(200)
,Gender CHAR(10)
)
INSERT INTO @Employee VALUES(1,'Alpesh','Male')
INSERT INTO @Employee VALUES(2,'Devang','Male')
INSERT INTO @Employee VALUES(3,'Pankaj','Male')
INSERT INTO @Employee VALUES(4,'Saheen','Female')
INSERT INTO @Employee VALUES(6,'Ajay','Male')
INSERT INTO @Employee VALUES(7,'Sakshi','Female')
INSERT INTO @Employee VALUES(8,'Ajay','Male')
INSERT INTO @Employee VALUES(9,'ifra','female')
SELECT *
FROM @Employee
WHERE Gender = @Gender
OR @Gender IS NULL
END
Output
EXEC Employee_GetDetailsBasedonGender NULL
Eid |
Name |
Gender |
1 |
Alpesh |
Male |
2 |
Devang |
Male |
3 |
Pankaj |
Male |
4 |
Saheen |
Female |
6 |
Ajay |
Male |
7 |
Sakshi |
Female |
8 |
Ajay |
Male |
9 |
ifra |
female |
EXEC Employee_GetDetailsBasedonGender 'Male'
Eid |
Name |
Gender |
1 |
Alpesh |
Male |
2 |
Devang |
Male |
3 |
Pankaj |
Male |
6 |
Ajay |
Male |
8 |
Ajay |
Male |
EXEC Employee_GetDetailsBasedonGender 'Female'
Eid |
Name |
Gender |
4 |
Saheen |
Female |
7 |
Sakshi |
Female |
9 |
ifra |
female |