Quantcast
Channel: SQLServerCentral » SQL Server 2014 » Development - SQL Server 2014 » Latest topics
Viewing all articles
Browse latest Browse all 3145

Select within Case Statement

$
0
0
I have the following select statement where i am trying to pull period Revenue along with Total Revenue for engagements. The Rev_main table has a period column so i am trying to setup the case statement so that it will pull the period Revenue based on the period of the system date. We have a CalcPeriod function that will return the period of a date field in a table but we need today's date. Right now just to get data to pull into my query, i hard coded this months period. Ideally i would like the Current Syntax[code="sql"] SELECT rev.sales_doc_no , period_rev = SUM(CASE WHEN period = '201704' THEN amount ELSE 0 END) , todate_rev = SUM(amount) FROM rev_main rev GROUP BY rev.sales_doc_no;[/code]Expected Syntax[code="sql"]Select rev.sales_doc_no period_rev = SUM(CASE WHEN Period = select dbo.calcperiod(value) from sys_registry where system_code = 'gbl' and name = 'reportdate' THEN amount ELSE 0 END), todate_rev = SUM(amount)FROM rev_main revGroup By rev.sales_doc_no[/code]Any thoughts?

Viewing all articles
Browse latest Browse all 3145

Trending Articles