Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Get months from a date range comparing event date

$
0
0

Hi All,

Below is the data

CREATE TABLE #Coverage(
EmployeeID INT,
EmployeeName VARCHAR(20),
CoverageName VARCHAR(50),
CoverageAmount Decimal,
CoveredBy VARCHAR(20),
EventDate DATETIME,
CoverageStartDate DATETIME,
CoverageEndDate DATETIME
)

INSERT INTO #coverage VALUES (8,'Lara','Employee + Children',213.60,'EmployeeContribution','2013-10-01','2013-10-01','2014-05-31'),
(8,'LAra','Employee + Children',	606.31	,'CompanyContribution'	,'2013-10-01','2013-10-01','2014-05-31'),
(8,'LAra','Employee Only'			,0.00	,'EmployeeContribution'	,NULL	,'2013-06-01','2014-05-31'),
(8,'LAra','Employee Only'			,431.55	,'CompanyContribution'	,NULL	,'2013-06-01','2014-05-31'),
(8,'LAra','Employee Only'			,81.42	,'EmployeeContribution'	,NULL	,'2012-06-01','2013-05-31'),
(8,'LAra','Employee Only'			,420.93	,'CompanyContribution'	,NULL	,'2012-06-01','2013-05-31')

SELECT * FROM #Coverage

drop table #coverage

and expected out put for the year 2013

EmployeeIDEmployeeNameCoverageNameCoverageAmountCoveredByMonthYear
8LaraEmployee Only81Employee Contibution12013
8LaraEmployee Only421Company Contribution12013
8LaraEmployee Only81Employee Contibution22013
8LaraEmployee Only421Company Contribution22013
8LaraEmployee Only81Employee Contibution32013
8LaraEmployee Only421Company Contribution32013
8LaraEmployee Only81Employee Contibution42013
8LaraEmployee Only421Company Contribution42013
8LaraEmployee Only81Employee Contibution52013
8LaraEmployee Only421Company Contribution52013
8LaraEmployee Only81Employee Contibution62013
8LaraEmployee Only421Company Contribution62013
8LaraEmployee Only81Employee Contibution72013
8LaraEmployee Only421Company Contribution72013
8LaraEmployee Only81Employee Contibution82013
8LaraEmployee Only421Company Contribution82013
8LaraEmployee Only81Employee Contibution92013
8LaraEmployee Only421Company Contribution92013
8LaraEmployee +Children214Employee Contibution102013
8LaraEmployee +Children606Company Contribution102013
8LaraEmployee +Children214Employee Contibution112013
8LaraEmployee +Children606Company Contribution112013
8LaraEmployee +Children214Employee Contibution122013
8LaraEmployee +Children606Company Contribution122013

Can any one help me out with this.

Thanks!


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>