0

嘿,我在存储过程中很新,我有类似的程序

ALTER procedure [dbo].[list_of_employee]
(
  @employee_id int
 )
 as 
begin 
select *from project_employee_rel PE
inner join employee_details E on E.employee_id=PE.employee_id
inner join project_details P on P.project_id=PE.project_id 
where PE.employee_id=@employee_id

select * from employee_details 
where employee_id=@employee_id
end 

它分别返回两个结果我想要这样的结果'如果第一个查询返回空行或 null 然后第二个查询被执行否则不请帮助我提前谢谢

4

2 回答 2

1

尝试这个

ALTER procedure [dbo].[list_of_employee]
(
  @employee_id int
)
as 
BEGIN
  DECLARE @Count int
  SET @Count = select COUNT(PRIMARYKEY COLUMN) from project_employee_rel PE
    inner join employee_details E on E.employee_id=PE.employee_id
    inner join project_details P on P.project_id=PE.project_id 
    where PE.employee_id=@employee_id
  IF (@Count>0)
   BEGIN
      select *from project_employee_rel PE
       inner join employee_details E on E.employee_id=PE.employee_id
       inner join project_details P on P.project_id=PE.project_id 
       where PE.employee_id=@employee_id
   END

  ELSE
   BEGIN
       select * from employee_details 
       where employee_id=@employee_id
   END
END 
于 2013-02-28T11:32:22.840 回答
0
IF Check Count of your first query
  return result set
ELSE 
  return other result set
END
于 2013-02-28T11:28:05.653 回答