jeudi 27 août 2015

Condition based where clause sql procedure

Hi can some one suggest me how to add a condition in where clause of my stored procedure? Here is my procedure

CREATE Procedure getAllEmployeesByDeptAndFlag
@Dept int,
@sal int,
@Flag int
as
if @flag = 1
    select * from employee where Department = @dept and @sal < 10000
else 
    select * from employee where Department = @dept

Is there any way to simplify above procedure?

Aucun commentaire:

Enregistrer un commentaire