Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE TABLE [dbo].[RawDataTable] (
- [Id] INT IDENTITY (1, 1) NOT NULL,
- [CheckDate] DATE NULL,
- [PropNum] INT NOT NULL,
- [PropSeqNum] INT NULL,
- [PropName] NVARCHAR (100) NOT NULL,
- [ProductionMonth] INT NULL,
- [Product] INT NOT NULL,
- [LeaseVolume] DECIMAL (18, 2) NOT NULL,
- [Price] DECIMAL (18, 2) NOT NULL,
- [LeaseGrossValue] DECIMAL (18, 2) NOT NULL,
- [LeaseTaxes] DECIMAL (18, 2) NULL,
- [LeaseOtherDeductions] DECIMAL (18, 2) NOT NULL,
- [LeaseNetValue] DECIMAL (18, 2) NOT NULL,
- [DisbursementDecimal] DECIMAL (18) NULL,
- [InterestType] NVARCHAR (10) NULL,
- [InterestGrossValue] DECIMAL (18, 2) NOT NULL,
- [InterestTaxes] DECIMAL (18, 2) NOT NULL,
- [IntrestOtherDeductions] DECIMAL (18, 2) NOT NULL,
- [InterestNetValue] DECIMAL (18, 2) NOT NULL,
- PRIMARY KEY CLUSTERED ([Id] ASC)
- );
- CREATE PROCEDURE [dbo].[EraseDuplicates]
- @TVP dbo.TVP READONLY
- AS
- SELECT * INTO dbo.#Temp FROM @TVP
- UPDATE T1
- SET T1.LeaseVolume = 0,
- T1.Price = 0,
- T1.LeaseGrossValue = 0,
- T1.LeaseTaxes = 0,
- T1.LeaseOtherDeductions = 0,
- T1.LeaseNetValue = 0
- FROM
- (SELECT *
- FROM dbo.#Temp
- WHERE Product >= 400 OR
- Id NOT IN
- (SELECT MIN(Id)
- FROM dbo.#Temp
- GROUP BY CheckDate, PropNum, PropSeqNum, PropName, ProductionMonth, Product)) AS T1
- INSERT INTO RawDataTable
- SELECT *
- FROM #Temp
- RETURN 0
- CREATE PROCEDURE [dbo].[CalculateTotals]
- @startMonth int,
- @endMonth int
- AS
- DECLARE @date DATE =
- (SELECT EOMONTH(MAX(CheckDate))
- FROM RawDataTable
- WHERE MONTH(CheckDate) >= @startMonth AND
- MONTH(CheckDate) <= @endMonth)
- INSERT INTO RawDataTable
- (
- CheckDate,
- PropNum,
- PropSeqNum,
- PropName,
- ProductionMonth,
- Product,
- LeaseVolume,
- Price,
- LeaseGrossValue,
- LeaseTaxes,
- LeaseOtherDeductions,
- LeaseNetValue,
- DisbursementDecimal,
- InterestType,
- InterestGrossValue,
- InterestTaxes,
- IntrestOtherDeductions,
- InterestNetValue
- )
- SELECT
- CheckDate = @date,
- PropNum,
- PropSeqNum = NULL,
- PropName,
- ProductionMonth = NULL,
- Product,
- SUM(LeaseVolume) AS LeaseVolume,
- SUM(Price) AS Price,
- SUM(LeaseGrossValue) AS LeaseGrossValue,
- SUM(LeaseTaxes) AS LeaseTaxes,
- SUM(LeaseOtherDeductions) AS LeaseOtherDeductions,
- SUM(LeaseNetValue) AS LeaseNetValue,
- DisbursementDecimal = NULL,
- InterestType = NULL,
- SUM(InterestGrossValue) AS InterestGrossValue,
- SUM(InterestTaxes) AS InterestTaxes,
- SUM(IntrestOtherDeductions) AS IntrestOtherDeductions,
- SUM(InterestNetValue) AS InterestNetValue
- FROM RawDataTable
- WHERE MONTH(CheckDate) >= @startMonth AND
- MONTH(CheckDate) <= @endMonth
- GROUP BY PropNum, PropName, Product
- RETURN 0
- CheckDate PropNum PropSeqNum PropName ProductionMonth Product LeaseVolume Price LeaseGrossValue LeaseTaxes LeaseOtherDeductions LeaseNetValue DisbursementDecimal InterestType InterestGrossValue InterestTaxes IntrestOtherDeductions InterestNetValue
- 1/25/2015 100004 25 A 122014 100 774.96 51.93 40243.64 -4628.03 0 35615.61 0.0026932 RI 01 108.38 -12.46 0 95.92
- 1/25/2015 100004 25 A 122014 100 774.96 51.93 40243.64 -4628.03 0 35615.61 0.0050669 RI 02 203.91 -23.45 0 180.46
- CheckDate PropNum PropSeqNum PropName ProductionMonth Product LeaseVolume Price LeaseGrossValue LeaseTaxes LeaseOtherDeductions LeaseNetValue DisbursementDecimal InterestType InterestGrossValue InterestTaxes IntrestOtherDeductions InterestNetValue
- 1/25/2015 100004 25 A 122014 100 774.96 51.93 40243.64 -4628.03 0 35615.61 0.0026932 RI 01 108.38 -12.46 0 95.92
- 1/25/2015 100004 25 A 122014 100 0.00 0.00 0.00 0.00 0 0.00 0.0050669 RI 02 203.91 -23.45 0 180.46
- Qtr1Total 100004 25 A 122014 100 774.96 51.93 40243.64 -4628.03 0 35615.61 0.0026932 RI 01 312.29 -35.91 0 276.38
- 1/25/2015 100004 25 A 122014 100 774.96 51.93 40243.64 -4628.03 0.00 35615.61 0 RI 01 108.38 -12.46 0.00 95.92
- 1/25/2015 100004 25 A 122014 100 774.96 51.93 40243.64 -4628.03 0.00 35615.61 0 RI 01 108.38 -12.46 0.00 95.92
- 1/25/2015 100004 25 A 122014 100 0.00 0.00 0.00 0.00 0.00 0.00 0 RI 02 203.91 -23.45 0.00 180.46
- 1/25/2015 100004 25 A 122014 100 0.00 0.00 0.00 0.00 0.00 0.00 0 RI 02 203.91 -23.45 0.00 180.46
- 1/31/2015 100004 A 122014 100 1549.92 103.86 80487.28 -9256.06 0.00 71231.22 624.58 -71.82 0.00 552.76
- 1/31/2015 100004 A 122014 100 3099.84 207.72 160974.56 -18512.12 0.00 142462.44 1249.16 -143.64 0.00 1105.52
- 1/31/2015 100004 A 122014 100 6199.68 415.44 321949.12 -37024.24 0.00 284924.88 2498.32 -287.28 0.00 2211.04
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement