我怎麼會去修改存儲過程運行兩個SQL語句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 [email protected]_id
return
修改2 ----- 他們可以有multple合約,但可以有multple sallarys
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 [email protected]_id
return
hi marc它可以是multle sallarys,因爲它們可以有不同的合約,所以需要添加多個,如果發現基地從第一query.contract id它的SQL 2008 R2 – rogue39nin
是的,但看看我的第二次修改把這個現在 – rogue39nin