select within select and parameters

 

SELECT (SELECTSUM(t.TepTotal)

FROM[RELET2007].[dbo].[RELETProjectsReports]r

INNERJOIN[RELET2007].[dbo].[RELETProjectsReportsTEP]tonr.RELETPRPID=t.RELETPRPID


  

Wherer.TEDACReceiveDate<'10-1-2014'


  

ANDr.AcceptedDate>='2-1-2015'


AND

r.AcceptedDate<'2-10-2015')'Backlog',


 

(SELECTSUM(t.TepTotal)


 

FROM[RELET2007].[dbo].[RELETProjectsReports]r

 

INNERJOIN[RELET2007].[dbo].[RELETProjectsReportsTEP]tonr.RELETPRPID=t.RELETPRPID


 

Wherer.TEDACReceiveDate>='10-1-2014'


 

ANDr.AcceptedDate>='2-1-2015'


AND

r.AcceptedDate<'2-10-2015')'REST OF WORLD';

September 14th, 2015 10:35am

Hi mkatyal,

For readability Iv format your query. The query looks good, what is your question then?
SELECT (
		SELECT SUM(t.TepTotal)
		FROM [RELET2007].[dbo].[RELETProjectsReports] r
		INNER JOIN [RELET2007].[dbo].[RELETProjectsReportsTEP] tonr.RELETPRPID = t.RELETPRPID
		WHERE r.TEDACReceiveDate < '10-1-2014' ANDr.AcceptedDate >= '2-1-2015'
			AND r.AcceptedDate < '2-10-2015'
		) 'Backlog'
	,(
		SELECT SUM(t.TepTotal)
		FROM [RELET2007].[dbo].[RELETProjectsReports] r
		INNER JOIN [RELET2007].[dbo].[RELETProjectsReportsTEP] tonr.RELETPRPID = t.RELETPRPID
		WHERE r.TEDACReceiveDate >= '10-1-2014' ANDr.AcceptedDate >= '2-1-2015'
			AND r.AcceptedDate < '2-10-2015'
		) 'REST OF WORLD';


Free Windows Admin Tool Kit Click here and download it now
September 14th, 2015 10:48pm

You can avoid the subqueries and make it like this for simplicity

SELECT SUM(CASE WHEN r.TEDACReceiveDate < '10-1-2014' THEN t.TepTotal ELSE 0 END) AS [Backlog], 
SUM(CASE WHEN r.TEDACReceiveDate >= '10-1-2014' THEN t.TepTotal ELSE 0 END) AS [REST OF WORLD]
FROM [RELET2007].[dbo].[RELETProjectsReports] r
INNER JOIN [RELET2007].[dbo].[RELETProjectsReportsTEP] tonr ON tonr.RELETPRPID=t.RELETPRPID
Where r.AcceptedDate>='2-1-2015'
AND  r.AcceptedDate < '2-10-2015';

September 15th, 2015 2:21am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics