tsql - SQL Statement to get contract renewal amount by time range -
i have 2 views. 1 view shows me expiration dates of contracts of customer. other 1 returning start dates of customer's contracts. wan't find out renewal amount of expired contract. rule is, customer has start contract in 90 days after contract expired.
pretend analysis period jan 2013. have expiration amount of 2835,15. have 2 (2835, 1596) contract starts in next 90 days after expiration.
i need query result:
tried lot of statements found no way result. ides?
thanks
here's answer i've tried
table 1 :
use [nmiifdb_dev] go /****** object: table [dbo].[tes1] script date: 5/3/2013 4:20:35 pm ******/ set ansi_nulls on go set quoted_identifier on go create table [dbo].[tes1]( [contractenddate] [date] null, [customerno] [nvarchar](50) null, [contractamount] [numeric](18, 2) null ) on [primary] go table 2
use [nmiifdb_dev] go /****** object: table [dbo].[tes2] script date: 5/3/2013 4:20:46 pm ******/ set ansi_nulls on go set quoted_identifier on go create table [dbo].[tes2]( [contractstartdate] [date] null, [customerno] [nvarchar](50) null, [contractamount] [numeric](18, 2) null ) on [primary] go select statement
select year(t1.contractenddate) expirationyear, month(t1.contractenddate) expirationmonth, t1.contractamount expirationamount, sum(t2.contractamount) renewalamount tes1 t1, tes2 t2 month(t1.contractenddate) = 01 , year(t1.contractenddate) = 2013 , month(t2.contractstartdate) = 01 , year(t2.contractstartdate) = 2013 group year(t1.contractenddate), month(t1.contractenddate), t1.contractamount you can declare parameter want compare in parentheses
Comments
Post a Comment