Support #1821 » CBIATMTOPYCPOTARIF.sql
1 |
--CREATE PROCEDURE CBIATMTOPYCPOTARIF
|
---|---|
2 |
--(
|
3 |
-- @EmployeeID VARCHAR(20)
|
4 |
-- ,@StartDate VARCHAR(20)
|
5 |
-- ,@EndDate VARCHAR(20)
|
6 |
--)
|
7 |
--AS
|
8 |
|
9 |
DECLARE @EmployeeID VARCHAR(20) = '06120011' |
10 |
DECLARE @StartDate VARCHAR(20) = '20221101' |
11 |
DECLARE @EndDate VARCHAR(20) = '20221130' |
12 |
|
13 |
DECLARE @CTARIF TABLE |
14 |
(
|
15 |
EmployeeID VARCHAR(20) |
16 |
,CPORett DECIMAL(22,2) |
17 |
,CPO2Rett DECIMAL(22,2) |
18 |
,CPO3Rett DECIMAL(22,2) |
19 |
)
|
20 |
|
21 |
INSERT INTO @CTARIF |
22 |
SELECT @EmployeeID, * FROM (SELECT FieldName, Tarif FROM CTARIFCPO ) AS SourceTable |
23 |
PIVOT (MAX(Tarif) |
24 |
FOR FieldName IN |
25 |
( [CPORett], |
26 |
[CPO2Rett], |
27 |
[CPO3Rett]) |
28 |
) AS pvt |
29 |
|
30 |
SELECT DISTINCT md.EmployeeID, md.CPORett, md.CPO2Rett, md.CPO3Rett |
31 |
,md.CPORett * tarif.CPORett AS TarifCPORett |
32 |
,md.CPO2Rett * tarif.CPO2Rett AS TarifCPO2Rett |
33 |
,md.CPO3Rett * tarif.CPO3Rett AS TarifCPO3Rett |
34 |
FROM dbo.CUSPYDATACPO AS md |
35 |
LEFT JOIN @CTARIF AS tarif |
36 |
ON md.EmployeeID = tarif.EmployeeID |
37 |
WHERE md.EmployeeID = @EmployeeID |
38 |
AND (md.StartDate BETWEEN @StartDate AND @EndDate) |