Have added the following code to my SQL query: (Note cut down version)
DECLARE @rowType AS TABLE (
rowTypeLabel NVARCHAR (20));
INSERT INTO @rowType
VALUES ('Cumulative');
INSERT INTO @rowType
VALUES ('Non-Cumulative');
--select * from @rowType
SELECT ID,Name,StartDate,
EndDate,
rowTypeLabel AS Period
FROM dbo.sicky CROSS JOIN @rowType
WHERE (rowTypeLabel = 'Cumulative'
OR (rowTypeLabel = 'Non-Cumulative'
AND (EndDate IS NULL
OR EndDate BETWEEN CAST (DateAdd(Day, 1 - Day(getDate()), getdate()) AS DATE) AND CAST (DateAdd(month, 1, DateAdd(Day, -Day(getDate()), getdate())) AS DATE))));
Run time has gone from around 10 minutes to around 1 hour, does anyone have any suggestions as to why this may be, the results without this cross join were around 46,000 and after brings back an additional 231 rows (anything that is classed as 'non-cumulative' as per query.