0

嗨,我有这个用于搜索员工信息的存储过程。我希望用户可以选择输入 ID、名字或姓氏。但是当我执行这个存储过程时,它需要其他参数。

  create proc searchtry
  @empID int,
  @firstname varchar(20),
  @lastname varchar(20)
  as
  begin
  select fld_EmployeeId,fld_EmployeeFirstName,fld_EmployeeLastName
  from Reference.tbl_EmployeeDetails
  where fld_EmployeeId  like @empID
  OR fld_EmployeeFirstName  like @firstname
  OR fld_EmployeeLastName  like @lastname
  end 
4

1 回答 1

0

您应该为参数提供默认值

create proc searchtry
  @empID int = NULL,
  @firstname varchar(20) = '',
  @lastname varchar(20) = ''
  as
  begin
  select fld_EmployeeId,fld_EmployeeFirstName,fld_EmployeeLastName
  from Reference.tbl_EmployeeDetails
  where fld_EmployeeId  like @empID
  OR fld_EmployeeFirstName  like @firstname
  OR fld_EmployeeLastName  like @lastname
  end 
于 2013-07-30T10:52:25.773 回答