SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
go
ALTER PROCEDURE [dbo].[ProjectMonthReport] ( @in_enddate DATETIME )
AS
BEGIN
DECLARE @date DATETIME
DECLARE @lastdaynextyear DATETIME
DECLARE @lastdaypremonth DATETIME
SET @date = @in_enddate
--年初,计算给定日期所在年的第一天
SET @lastdaynextyear = ( SELECT DATEADD(year, DATEDIFF(year, 0, @date),
0)
)
SET @lastdaypremonth = ( SELECT DATEADD(ms, -3,
DATEADD(mm,
DATEDIFF(mm, 0,
@in_enddate), 0))
)
DECLARE @in_nc1 BIGINT
DECLARE @in_nc2 BIGINT
DECLARE @in_nc3 DECIMAL(18, 6)
DECLARE @in_nc4 DECIMAL(18, 6)
DECLARE @in_qc1 BIGINT
DECLARE @in_qc2 BIGINT
DECLARE @in_qc3 DECIMAL(18, 6)
DECLARE @in_qc4 DECIMAL(18, 6)
SET @in_nc1 = ( SELECT COUNT(DISTINCT customerid)
FROM T_ProjectInfo
WHERE DeleteMark <> 1
AND CreateDate < @lastdaynextyear
)
SET @in_nc2 = ( SELECT COUNT(1)
FROM T_ProjectInfo
WHERE DeleteMark <> 1
AND CreateDate < @lastdaynextyear
)
SET @in_nc3 = ( SELECT ISNULL(SUM(LoanAmount), 0)
FROM T_ProjectInfo
WHERE DeleteMark <> 1
AND CreateDate < @lastdaynextyear
)
SET @in_nc4 = ( SELECT ISNULL(SUM(LoanAmount), 0)
FROM T_ProjectInfo
WHERE DeleteMark <> 1
AND CreateDate < @lastdaynextyear
)
SET @in_qc1 = ( SELECT COUNT(DISTINCT customerid)
FROM T_ProjectInfo
WHERE DeleteMark <> 1
AND CreateDate <= @lastdaypremonth
)
SET @in_qc2 = ( SELECT COUNT(1)
FROM T_ProjectInfo
WHERE DeleteMark <> 1
AND CreateDate <= @lastdaypremonth
)
SET @in_qc3 = ( SELECT ISNULL(SUM(LoanAmount), 0)
FROM T_ProjectInfo
WHERE DeleteMark <> 1
AND CreateDate <= @lastdaypremonth
)
SET @in_qc4 = ( SELECT ISNULL(SUM(LoanAmount), 0)
FROM T_ProjectInfo
WHERE DeleteMark <> 1
AND CreateDate <= @lastdaypremonth
)
CREATE TABLE #temp1
(
nc1 BIGINT ,
nc2 BIGINT ,
nc3 DECIMAL(18, 6) ,
nc4 DECIMAL(18, 6) ,
qc1 BIGINT ,
qc2 BIGINT ,
qc3 DECIMAL(18, 6) ,
qc4 DECIMAL(18, 6) ,
xz11 BIGINT ,
xz12 BIGINT ,
xz13 BIGINT ,
xz21 BIGINT ,
xz22 BIGINT ,
xz23 BIGINT ,
xz31 BIGINT ,
xz32 BIGINT ,
xz33 BIGINT ,
xz41 DECIMAL(18, 6) ,
xz42 DECIMAL(18, 6) ,
xz43 DECIMAL(18, 6) ,
xz51 DECIMAL(18, 6) ,
xz52 DECIMAL(18, 6) ,
xz53 DECIMAL(18, 6) ,
js11 BIGINT ,
js12 BIGINT ,
js21 BIGINT ,
js22 BIGINT ,
js31 DECIMAL(18, 6) ,
js32 DECIMAL(18, 6) ,
qm1 BIGINT ,
qm2 BIGINT ,
qm3 DECIMAL(18, 6) ,
qm4 BIGINT ,
qm5 BIGINT ,
qm6 DECIMAL(18, 6) ,
qm7 DECIMAL(18, 6) ,
zaj11 BIGINT ,
zaj12 BIGINT ,
zaj13 BIGINT ,
zaj21 DECIMAL(18, 6) ,
zaj22 DECIMAL(18, 6) ,
zaj23 DECIMAL(18, 6) ,
zaj31 DECIMAL(18, 6) ,
zaj32 DECIMAL(18, 6) ,
zaj33 DECIMAL(18, 6) ,
wd11 BIGINT ,
wd12 BIGINT ,
wd13 BIGINT ,
wd21 BIGINT ,
wd22 BIGINT ,
wd23 BIGINT ,
wd31 DECIMAL(18, 6) ,
wd32 DECIMAL(18, 6) ,
wd33 DECIMAL(18, 6),
)
INSERT INTO #temp1
( nc1 ,--1
nc2 ,--2
nc3 ,
nc4 ,
qc1 ,
qc2 ,
qc3 ,
qc4 ,--8
xz11 ,
xz12 ,
xz13 ,
xz21 ,
xz22 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