如何在SQL 2005中组合返回两个结果的存储过程结果

本文关键字:结果 两个 存储过程 返回 SQL 2005 组合 | 更新日期: 2023-09-27 18:01:44

嘿,我是存储过程中的新手,我有这样的过程

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然后第二个查询得到执行,否则不是请帮帮我提前感谢

如何在SQL 2005中组合返回两个结果的存储过程结果

试试这个

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 
IF Check Count of your first query
  return result set
ELSE 
  return other result set
END