Support #1822 » CBIATMTOPYHINOTARIF.sql
1 |
ALTER PROCEDURE CBIATMTOPYHINOTARIF |
---|---|
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) = '20221201'
|
11 |
--DECLARE @EndDate VARCHAR(20) = '20221231'
|
12 |
|
13 |
DECLARE @CTARIF TABLE |
14 |
(
|
15 |
EmployeeID VARCHAR(20) |
16 |
,QtyTrip1 DECIMAL(22,0) |
17 |
,QtyTrip2 DECIMAL(22,0) |
18 |
,QtyTrip3 DECIMAL(22,0) |
19 |
)
|
20 |
|
21 |
INSERT INTO @CTARIF |
22 |
SELECT @EmployeeID, * FROM (SELECT FieldName, Tarif FROM CTARIFHINO) AS SourceTable |
23 |
PIVOT (MAX(Tarif) |
24 |
FOR FieldName IN |
25 |
( [QtyTrip1], |
26 |
[QtyTrip2], |
27 |
[QtyTrip3]) |
28 |
) AS pvt |
29 |
|
30 |
SELECT DISTINCT md.EmployeeID, md.QtyTrip1, md.QtyTrip2, md.QtyTrip3 |
31 |
,md.QtyTrip1 * tarif.QtyTrip1 AS TarifQtyTrip1 |
32 |
,md.QtyTrip2 * tarif.QtyTrip2 AS TarifQtyTrip2 |
33 |
,md.QtyTrip3 * tarif.QtyTrip3 AS TarifQtyTrip3 |
34 |
FROM dbo.CUSPYDATAPREMIHINO 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) |
- « Previous
- 1
- 2
- 3
- Next »