我将如何修改存储过程以运行两个 SQL 语句
CREATE procedure [dbo].[hms_GetEmployeeSalaryRecordsByContractId]
(
@Id int
)
as
SELECT c.*
FROM contract c
where c.emp_no = @Id AND c.leave_date='1900-01-01 00:00:00.000' and c.main_contract=1
select * from salary s where s.contract_id = firstquery.contract_id
以上可以根据一份合同找到两条工资记录
如果找到多个薪水,那么我需要sum(s.salary)
在存储过程中将其作为十进制值返回。
到目前为止我已经这样做了
USE [pamsv83x]
GO
/****** Object: StoredProcedure [dbo].[hms_GetEmployeeSalaryRecordsByContractId] Script Date: 08/29/2013 10:45:05 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
Create procedure [dbo].[hms_GetEmployeeSalaryRecordsByContractEmpNo]
(
@Id int,
@sallaryresult decimal(8,2) OUTPUT
)
as
DECLARE @contract_id int
DECLARE @totalsallary decimal(8,2)
set @contract_id=(SELECT c.contract_id
FROM contract c
where c.emp_no = @Id AND c.leave_date='1900-01-01 00:00:00.000' and c.main_contract=1)
SELECT *,SUM(salary)
from salary s
where s.emp_no=@contract_id
return
修改 2----- 他们可以有多个合同,但可以有多个薪水
Create procedure [dbo].[hms_GetEmployeeSalaryRecordsByContractEmpNo]
(
@Id int,
@sallaryresult decimal(8,2) OUTPUT
)
as
DECLARE @contract_id int
DECLARE @totalsallary decimal(8,2)
set @contract_id=(SELECT c.contract_id
FROM contract c
where c.emp_no = @Id AND c.leave_date='1900-01-01 00:00:00.000')
SELECT *,SUM(salary + old_salary)
from salary s
where s.contract_id=@contract_id
return