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.

http://d.pr/i/biti

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:

http://d.pr/i/3zty

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

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -