Group By Financial Quarter

Dec 4, 2007

I have a transaction file with Company_code,Gl_code,Amount,Transaction_Date

I want to sum the amount based on a Company_Code,Glcode for every financial quarter(01/04/2007-30/06/2007,01/07/2007-30/09/2007 and so on).

Expected Output

Company_Code,Gl_code,Quarter_1,Amount_1,Quarter_2,Amount_2,Quarter_3,Amount_3,Quarter_4,Amount_4

Regards

Nirene

View 6 Replies


ADVERTISEMENT

Sql For Financial Reporting Periods This Month, Last Month, This Quarter, Last Quarter, This Year, Last Year

Oct 26, 2006

Does anyone know of a way to use a funtion for returning records based on fiscal reporting periods like Quickbooks uses for example "This Month", "Last Month", "This Quarter", "Last Quarter", "This Year", "Last Year". While I realize that I can create a very long date time parsing routine  for this but it is not very elegant or useful. I thought there might be a way to do this already with an existing function.I have created a stored procedure that I pass a @ViewRange Parameter to and it returns the records that I want but I need this ability in several procedures and wanted to turn it into a stored procedure.IF @ViewRange = 'This Month' SELECT TOP 20 Customer.LastName AS Customer, SUM(Sales.AmtCharge) AS Amount FROM Customer INNER JOIN Sales ON Customer.CustNo = Sales.CustNo WHERE (MONTH(Sales.InvDate) = MONTH(CURRENT_TIMESTAMP)) AND (YEAR(Sales.InvDate) = YEAR(CURRENT_TIMESTAMP)) GROUP BY Customer.LastName ORDER BY SUM(Sales.AmtCharge) DESC;IF @ViewRange = 'Last Month' SELECT TOP 20 Customer.LastName AS Customer, Sum(Sales.AmtCharge) AS Amount FROM Customer INNER JOIN Sales ON Customer.CustNo = Sales.CustNo WHERE(MONTH(Sales.InvDate) = MONTH(CURRENT_TIMESTAMP) - 1) And (YEAR(Sales.InvDate) = YEAR(CURRENT_TIMESTAMP)) GROUP BY Customer.LastName ORDER BY Sum(Sales.AmtCharge) DESC; Any ideas? 

View 8 Replies View Related

For Each Year Group In Matrix Return Last Quarter's Data

Sep 12, 2007

Hi, I have a matrix report with three data points
1. Inventory
2. Occupancy
3. Absorption

They are grouped in columns by Year and the data is returned by the query at Quarter granularity

My problem is that in the report, I need to display the Inventory data for the last quarter in each year however for Absorption it is the SUM of all 4 quarters

So, for 2006

Want Q4 data for Inventory, sum of all 4 quarters for Absorption

For 2007 Want Q2 data for Inventory (as it's the last loded quarter) and sum of Q1&Q2 for Absorption

How would I (or could I) do this in a Matrix Report - or is there a better way ?

View 6 Replies View Related

SQL Server 2012 :: Rollover Prior Quarter Data To New Quarter In A Table - Output Identity Values

Jun 5, 2014

I have a process to rollover prior quarter data to new quarter in a table.

For example, i have a table with (col1, col2, year, qtr) with data like ( Note: col1 is identity(1,1) )

1,'today',2014,1
2,'tomorrow,2014,1
3,'friday',2014,1

Now when i run my process, above 3 records will be rolled over new quarter 2014 Q2 and the table will be like

1,'today',2014,1
2,'tomorrow,2014,1
3,'friday',2014,1
4,'today',2014,2
5,'tomorrow,2014,2
6,'friday',2014,2

Row 1 with identity 1 has rolled over to new quarter row 4 with identity 4 ( qtr fields are changed )
Row 2 with identity 2 has rolled over to new quarter row 5 with identity 5. Same with last row as well.

Here, i have another table called "ident_map" with columns like (old identity, new identity ) and during rollover i am supposed to load ident_map table with old and new identity. So after rollover is complete, ident_map table should look like

1,4
2,5
3,6

I know using output clause I can capture the new identity values. 4,5,6 in this case. But is there any way to capture both old identity and new identity during rollover so that i can load the ident_map table with old and new identity.

View 9 Replies View Related

Financial Year

Sep 22, 2006

how can you store a financial year in sql 2005

View 5 Replies View Related

Financial Functions In SQL Server

Apr 10, 2002

Do we have any builtin functions in SQL Server for certain financial calculations. For eg., like the PV, FV functions in VB

If not, how else do we achieve this thru' a SQL Server stored procedure?

Thanks in advance,

Siva

View 1 Replies View Related

Financial Functions For SQL Server

Aug 17, 2006

Hi everybody,

Does anyone have financial functions to be run in SQL Server 2000? For example, future value, interest rate, payments, and so on. Or where can I find them on Internet?

Thanks in advance

Jaime

View 3 Replies View Related

Reporting Financial Ratings

Sep 10, 2007

I'm running into 'CLS-compliance' problems trying to use characters such as "+" and "-" as reporting fields. For example, Standard and Poors ratings have these characters to indicate a notch between main letter rating categories. I have reports that need to display distributions of these various ratings in column charts. However, the X axis labels refuse to print because of these characters!

Any suggestions? This is an awfully common type of labelling in this business!

Thanks

View 1 Replies View Related

Help Please. Select Data Between Financial Year

Feb 28, 2007

How can I select data between a financial year. The financial year begin in july(7) and end in june(6).

Lets say I want all data between the begining of financial year (7) to January (1)

so I would select all data between 7 and 1. (6 months period)

and lets say I want all data between the beginning of financial year(7) to october (10) so I would just select all data between 7 and 10. (3 months period).

Below is data from a customer table.


Customer Name Month
----------------------------------------------------
APPADENE FOREST PRODUCTS7
APPADENE FOREST PRODUCTS8
APPADENE FOREST PRODUCTS9
APPADENE FOREST PRODUCTS10
APPADENE FOREST PRODUCTS11
APPADENE FOREST PRODUCTS2
APPADENE FOREST PRODUCTS3
APPADENE FOREST PRODUCTS4
APPADENE FOREST PRODUCTS5
APPADENE FOREST PRODUCTS6
BLUELEAF CORPORATION PTY LTD3
BLUELEAF CORPORATION PTY LTD4
BLUELEAF CORPORATION PTY LTD5
WESPINE INDUSTRIES PTY LTD5
WESPINE INDUSTRIES PTY LTD6
WESPINE INDUSTRIES PTY LTD3
WESPINE INDUSTRIES PTY LTD4
WESPINE INDUSTRIES PTY LTD5
WESPINE INDUSTRIES PTY LTD6
BLUELEAF CORPORATION PTY LTD6
WESPINE INDUSTRIES PTY LTD8
WESPINE INDUSTRIES PTY LTD9
WESPINE INDUSTRIES PTY LTD11
WESPINE INDUSTRIES PTY LTD12
NANNUP TIMBER PROCESSING PTY LTD3
WESPINE INDUSTRIES PTY LTD1
NANNUP TIMBER PROCESSING PTY LTD4
NANNUP TIMBER PROCESSING PTY LTD5
NANNUP TIMBER PROCESSING PTY LTD6
WESPINE INDUSTRIES PTY LTD3

View 2 Replies View Related

Reporting Suspicious Financial Transactions

Jul 20, 2005

I want to monitor any suspicious financial transaction which takeplace in a bank through electronic transfer.There are three tables Customers, Account and transaction_type.How can I write a SQl to report the following:Detect an outbound Electronic transfer that is unusually high,compared to a set threshold.For each customer, generate alerts if any outbound Electronic Transferexceeds threshold.Detect Electronic Transfer that are high, compared to a set threshold.For each customer, generate alerts if any set of last 5 outboundElectronic Transfers exceeds the set threshold.Detect Electronic Transfer that are high, compared to historicalbehavior of the customer.For each customer, generate alerts if any set of last 5 ElectronicTransfer (the average of all sets of 5 outbound Electronic Transfer +2standard deviation points)

View 6 Replies View Related

Expert DBA Needed For A Large Financial Company!

Sep 10, 2004

I know, it's a job posting site, but our company is urgently looking for an expert senior level sql server DBA who can be rated as 9.5 out of 10 in sql server dba activities who are hard to find! Top hourly pay on a long contract in East Coast! so anyone interested? please rush resume to MessageDBfan@yahoo.com

View 1 Replies View Related

SQL Server 2012 :: Spreading Value Across Financial Year

Feb 28, 2015

I have a table which can be downloaded from the link below. The table contains property Market Rent and period the new rent is applicable. I need to generate a report with parameter ( year and month) so when the user inputs year and month the associated market rent amount for that month is listed.

For example if the 1st market rent update was done in June 2014 ( $300) and the 2nd in Dec 2014 $(350), the property market rent from June to Nov should be $300 and from Dec 2014 till the next rent update $350. So if user inputs year 2014 and month August, the amount is $300 and if the user enters the year 2015 and month March amount is $350

[URL] ....

Below is the table with sample data

DECLARE @table TABLE ( PropCode INT ,PropStartDate DATE ,PropEndDate char(10) ,PropRentStartDate DATE ,PropRentEndDate DATE ,MarketRent INT)
INSERT INTO @table (PropCode,PropStartDate, PropEndDate,PropRentStartDate,PropRentEndDate, MarketRent) VALUES
(2718, '2013-01-30', 'NULL', '2012-11-29', '2013-07-21', 289.20) ,(2718, '2013-01-30', 'NULL', '2013-07-22', '2013-11-24', 289.20) ,(2718, '2013-01-30', 'NULL', '2013-11-25', '2014-06-14', 289.20) ,(2718, '2013-01-30', 'NULL', '2014-06-15', '2014-11-30', 299.18) ,(2718, '2013-01-30', 'NULL', '2014-12-01', '2015-01-02', 299.18) ,(2718, '2013-01-30', 'NULL', '2015-01-03', '2050-01-01', 310.00) ,(3901, '2014-05-27', 'NULL', '2014-06-09', '2014-11-30', 400.00) ,(3901, '2014-05-27', 'NULL', '2014-12-01', '2050-01-01', 400.00) ,(3960, '2014-10-31', 'NULL', '2014-11-05', '2016-11-05', 470.00)

Select * from @table

View 3 Replies View Related

Calculate Contract Days In Financial Year

Feb 4, 2015

I have a table with 3 fields: Contract_No, Start_Date, End_Date. I need to calculate how many of the days between the Start and End dates fall within each financial year (FY) beginning 1st April and ending 31st March.

So for example if the Contract Start_Date is 26/01/2012 and the End_Date is 20/05/2012 or is null then the number of days for 2012 FY is 49 (counting from 01/04/2012 to 20/05/2012).

If the End_Date is null for the same contract, then the number of days for 2012 FY would be 365.

Since the contract period from Start_Date to End_Date might span more than one or even several FY I need to be able to show this in columns seperately for each FY. What is the best way of achieving this?

View 6 Replies View Related

Aggregating Financial Data To 1 Minute Intervals

Aug 19, 2006

I'm trying to create a query to return Open, Close, Max and Min Price for each 1 minute interval. Source data has two fields - Price, and Datestamp at 5 second intervals.

I can calculate the Max and Min (below) and set the datestamp to the middle of the interval, but get stuck on how to also return the Open and Close price for each interval.

SELECT MAX(price) AS MaxPrice, MIN(price) AS MinPrice,
DATEADD(ss, 30, DATEADD(n,DATEDIFF n, '1/1/2006', DateStamp),'1/1/2006')) AS DateStamp
FROM MasterData
GROUP BY DATEDIFF(n, '1/1/2006',DateStamp)

Any ideas?

thanks in advance.

View 1 Replies View Related

Reduce Row Spacing In Financial Reports - RS2005

Jan 30, 2007

I am using RS 2K5 to develop financial reports, with plenty of figures that must fit in a page.

I use tables for example. Fonts cannot be set smaller than 8pts.
I have also tried to decrease row height and to disable the "can grow to fit content" option, but of course in this way the text gets cut of in its lower part.

How can I do lines more compact? I need to reduce line spacing and to make the data more dense. Currently it looks very sparse.

Is it a known limitation for RS? Any workaround available? Any online example with dense reports?

Thank you.

View 1 Replies View Related

Design Question Relating To A Financial Application

May 20, 2008

EDIT: Please skip over this and go to the 2nd post. After writing this, I realized it may be too complicated to comprehend, so I tried to simplify with another example which is found in the 2nd post. Or if you want you can read this one and try to understand it.


I would like to go over a design we came up with to handle a certain reporting requirement from an OLAP cube to see if this is a good approach. Also, I would like to hear about other designs that we can consider.

Here is the condensed version of the requirement.

We are measuring the performance of a bunch of portfolios. So among other dimensions, we have a portfolio dimension that holds the list of portfolios we are tracking. In a typical portfolio analysis, an analyst almost always looks at a portfolio's measures along side a benchmark portfolio's measures. A benchmark is another portfolio against which a selected portfolio is compared. So, for a given portfolio, there is a determined benchmark portfolio.

For example, an analyst might want to look at a measure called Annual_Yield for a portfolio called Portfolio_A. There will be an attribute on the member Portfolio_A that tells us what its benchark portfolio is. That attribute will basically be another member from the portfolio dimension. So, as a function of what an analyst chooses as the first portfolio (the subject portfolio), the cube should be smart enought to know what to select as the second portfolio (the benchmark portfolio).

To implement this, I am proposing the following structure for the table that will create the portfolio dimension.

PortfolioID, PortfolioName, Attr1, Attr2, ..., AttrN, BenchMarkID
1, Portfolio_A, blah, blah, ...., blah, 3
2, Porfolio_B, blah, blah, ...., blah, 3
3, Portfolio_C, blah, blah, ...., blah, null
4, Portfolio_D, blah, blah, ...., blah, 3
5, Portfolio_E, blah, blah, ...., blah, 6
6, Portfolio_F, blah, blah, ...., blah, null

So, the above data says that Portfolios A, B, and D uses Portfolio C as their benchmarks. And Portfolio E uses Portfolio F as its benchmark. Lastly, if a portfolio is used as a benchmark for other portfolios, then its BenchmarkID is null, meaning it doesn't get compared to anything, thus Portfolios C and F have null BenchmarkIDs. With this data, I would create a hierarchy in the portfolio dimension that has two levels. At the top level, there will be a portfolio and if that portfolio has a benchmark, then it will drill down to it.

With a portfolio dimension designed as such, I envision a fact table that looks like the following.

PortfolioID, SomeOtherDimIDs,....., Annual_Yield
1, , blah, ,....., 10%
2, , blah, ,....., 7%
3, , blah, ,....., 0%
4, , blah, ,....., 15%
5, , blah, ,....., 20%
6, , blah, ,....., 9%

So, going back to the original report which was looking at Annual_Yield by Portfolio_A, I would do an MDX statement such as

With Set [PortfolioAndBenchmark] As
DESCEDANTS(Portfolio_A)

Select
[Annual_Yield], [PortfolioAndBenchmark] On Columns,
Whatever Other Dimension On Rows
From
[Cube]

Does this make sense? The only concern I have is that I don't want the measures to aggregate along the portfolio hierarchy.





View 1 Replies View Related

SQL Server 2012 :: Date Table For Financial Year

Dec 23, 2014

I need to create a table which holds date information for our financial year.

I have all the dates between now and 2045 and the start of the week and the end of the week. What I also have is the first sunday of the previous week in the spreadsheet too.

Please see below attachment

What I need to autofill once I import these three dates into a database is the week and the month.

The difficulty surrounding the month is that, we start a new month on the FIRST Sunday of the month.

So dates 07/04/14 to 04/05/2014 would be month 1.

Month 2 would begin on 05/05/2014 as it is the day after the first Sunday of the month, and so on....Month 5 would start on the 04/08/14.

Need to script something that would automatically calculate the week and month for me on the basis on above, if I have the start date, end date and 1st sunday already in a table?

View 9 Replies View Related

T-SQL (SS2K8) :: Returning Results That Fall Within Current Financial Year?

Jun 3, 2014

I am using MSSQL Server 2008R2 and I am interested in returning rows from a 'financial' table that fall within the current year (each row contains a 'Entered Date'). I am located in Australia so my financial year consists of all entries between the date 01/07/xx to the 30/06/yy.

Perhaps using the datediff() function, or other functions as required to achieve what I need?

View 3 Replies View Related

Reporting Services :: Set Financial Year Value Dynamically In SSRS Report

Jun 28, 2015

I have a requirement to display the count of project data by their status (On Hold,  In Progress, Pre-concept and Closed) for the current FY and Last FY based on column 'Financial Year' and 'Project Status'. 

Financial Year column has a value in the following format (FY2011-12, FY2012-13, FY2013-14,FY2014-15, FY2015-16,FY2019-20 ,FY2020-21,FY2021-22)
 
I need to set the financial year value dynamically in above format for the last and current year (FY2013-14, FY2014-15) based on today's date and  Financial Year is from July to Jun. For example,

When today's  date is 28-06-2015 then it should set the current FY as FY2014-15 and Last Financial Year as FY2013-14When today's  date is 28-06-2021 then it should set current FY as FY2020-21 and Last Financial Year as FY2019-20

View 3 Replies View Related

Query By Quarter

May 19, 2004

Hello, everyone:

There is a table named INCOME that has INCOME column for each day and DATE column starting from Aug. 29 1980. How to calculate income summary by each quarter? Thanks.

ZYT

View 9 Replies View Related

Calculate Quarter

Jan 28, 2007

Hi,

I need to retrieve both Mont and Quarter from an MS SQL server field containing a date as ''01/01/2007 12:10:00'.

Retrieving the Month is working properly, but getting some sql error with the Quarter function.

I will appreciate if someone can indicate me how should I do in order to retrieve the Quarter from a date.

To retrieve the month, I am using:

& "MONTH(STOCK.VALUEDATE) AS 'Month'"


To retrieve the Quarter, I am trying (but getting error):

& "QUARTER(STOCK.VALUEDATE) AS Quarter"
Thanks,

Aldo.

View 3 Replies View Related

Integration Services :: Data Extraction From Hyperion Financial Management Using SSIS

Jul 21, 2015

I want to build a data import process with SSIS, sourcing Hyperion Financial Management. Accoring to my knowldge there were a Star Integration Server (Star Analytics acquired by IBM in Feb 2013) doing the extraction job and which could be used in SSIS.

As this product is not available now, how to do this.

View 3 Replies View Related

Reporting Services :: Display Group Name Value Of Each Group In Column Header Outside The Group?

Sep 29, 2015

I have an SSRS 2012 table report with groups; each group is broken ie. one group for one page, and there are multiple groups in multiple pages.

'GroupName' column has multiple values - X,Y,Z,......

I need to group 'GroupName' with X,Y,Z,..... ie value X in page 1,value Y in page 2, value Z in page 3...

Now, I need to display another column (ABC) in this table report (outside the group column 'GroupName'); this outside column itself is another column header (not a group header) in the table (report) and it derives its name partly from the 'GroupName'  values:

Example:

Value X for GroupName in page 1 will mean, in page 1, column Name of ABC column must be ABC-X Value Y for GroupName in page 2 will mean, in page 2, column Name of ABC column must be ABC-Y Value Z for GroupName in page 3 will mean, in page 3, column Name of
ABC column must be ABC-Z

ie the column name of ABC (Clm ABC)  must be dynamic as per the GroupName values (X,Y,Z....)

Page1:

GroupName                 Clm ABC-X

X

Page2:

GroupName                 Clm ABC-Y

Y

Page3:

GroupName                 Clm ABC-Z

Z

I have been able to use First(ReportItems!GroupName.Value) in the Page Header to get GroupNames displayed in each page; I get X in page 1, Y in page 2, Z in page 3.....

However, when I use ReportItems (that refers to a group name) in the Report Body outside the group,

I get the following error:

Report item expressions can only refer to other report items within the same grouping scope or a containing grouping scope

I need to get the X, Y, Z ... in each page for the column ABC.

I have been able to use this - First(Fields!GroupName.Value); however, I get ABC-X, ABC-X, ABC-X in each of the pages for the ABC column, instead of ABC-X in page 1, ABC-Y in page 2, ABC-Z in page 3, ...

View 4 Replies View Related

Last Day Of Current Quarter + I Month

Feb 12, 2006

Hi there everbody,

i am trying to get the last day of the Q + 1 month

the first part i have succeeded (dateadd(ms,-3,DATEADD(qq, DATEDIFF(qq,0,getdate() )+1, 0))) ,but how do i add 1 more month ?

would appreciate any suggestion

regards

Yoav

View 2 Replies View Related

All Sales Reported After Quarter End

Apr 19, 2007

It's been a long time since I've built tough queries and need some help.

I need to report all sales that happened within a quarter but were reported after the quarter end.

Quarters

Q1 - 1/1 thru 3/31
Q2 - 4/1 thru 6/30
Q3 - 7/1 thru 9/30
Q4 - 10/1 thru 12/31

Sample Data

ticketid salespersonid saledate sale_entereddate
1234 bsmith 1/1/2006 2/1/2006
1235 jgarcia 3/31/2006 4/1/2006
1236 bsmith 1/1/2006 2/3/2006
1237 jdoe 6/23/2006 7/1/2006
1238 bsmith 8/5/2006 8/6/2006
1239 bsmith 10/1/2006 1/1/2007

View 4 Replies View Related

Quarter() Function In SSRS

Aug 1, 2007

I am uisng VS 2005 to build reports for SQL 2005. The problem is with getting the Quarter() function, mentioned in the BOL, to work in the report builder. When I build an expression and try to use the function as noted in the BOL I receive an error stating that the name "Quarter" is not declaired. When I use the expression builder to build the expression the function is not available in the builder, which is probably why I get the error.

I am assuming there is some sort of service pack of hot fix I need to apply to my VS but have not been able to locate which one. I have verified that I have all of the recent service packs applied for VS and SQL server 2005 but I am still unable to see/use this function.

Any help would be greatly appreciated. I need this function for my financial reports.

View 1 Replies View Related

Problem With QUARTER(date)

Apr 4, 2008

Hi,

I am using QUARTER(startdate) formula to retrieve the quarter of a specific datetime and to store in my calculated field in dataset. But while running its showing "error: [BC30451] Name 'QUARTER' is not declared".

Can anyone show me some light on this problem?

View 5 Replies View Related

Analysis :: Get Max Quarter Of A Year MDX?

Aug 18, 2015

There is a way to get the non empty max calendar quarter of the year and the last year. For example, the max calendar quarter of the last year should be 4, and in this moment the max quarter of this year should be 3.

I am building a report in SSRS and trying to avoid query the DWH database. I want to run every query against the cube.

View 3 Replies View Related

SQL Server 2012 :: Create View To Allocate Amount Per Month - Financial Year

Mar 21, 2015

I like to create an SQL view to divide amount 300,000 between 12 month starting from Month July 2014 to June 2015 as shown below

Amount Month Year
25,000 July 2014
25,000 August 2014
25,000 September 2014
25,000 October 2014
25,000 November 2014
25,000 December 2014
25,000 January 2015
25,000 February 2015
.
.
.
.

25,000 June 2015

View 7 Replies View Related

Power Pivot :: Sessions Conducted In X Years Prior To Chosen Financial Year

Jun 25, 2015

I have a simple 2 column dataset representing Date of session and Client Name (Please download workbook from here - [URL] ....  The Financial Year runs from April 1 to March 31.  I want to determine the number of sessions conducted in chosen financial year - 2.  So if I select FY 2015-16 in a slicer, then, I want view the number of session conducted client wise in FY 2013-14.  This is the formula calculated field formula I have written but when I drag this in the Pivot Table, I get an error message.  In the calculated field window, when I click on Check for errors, then there are no errors at all.

=CALCULATE([Sessions conducted],DATESBETWEEN(calendar[Dates],EDATE(FIRSTDATE(calendar[Dates]),-24),EDATE(FIRSTDATE(calendar[Dates]),-12)-1))

I cannot identify my error.

View 5 Replies View Related

Start Of The Week Of Current Quarter

Oct 2, 2014

I am trying to always get the start of the week of the current quarter in my criteria

This is the statement for the current quarter
Dateadd(qq, Datediff(qq,0,GetDate()), 0)

This is the statement for the current week
DATEADD(wk, DATEDIFF(wk,0,GETDATE()), 0)

How to calculate from the start of the week of the current quarter...

View 1 Replies View Related

Accumulate Months By Quarter Measurement

Mar 24, 2014

I need accumulate the months by Quarter measurement. For example we're in March now and I need put these code in Where clause like:

Where MyDate > DATEADD(mm, -11, DATEADD(mm, DATEDIFF(mm, 0, GETDATE()), 0)) ...

here DATEADD(mm, -11, DATEADD(mm, DATEDIFF(mm, 0, GETDATE()), 0)) makes Apr of last year included because that is the first month in 2nd Quarter of last year. But in next month we're in Apr and I need make -11 as -12 in above code to include Apr of last year. And same reason if we're in Feb. 2014 then I need change -11 to -10.

So how can I calculate this to make the number fit into the code or some other way to get the same effect? I need get all last 4 quarters based on current month (include current Quarter).

View 2 Replies View Related

Sum By Week / Month / Quarter / Year

Aug 20, 2014

I am trying to group counts by week,month,quarter, year for a particular activity type and I'm having issues.Here's my code so far:

SELECT
distinct
EmailAddressID,
emailaddress,
SUM(CASE WHEN [ActivityDate] >= DATEADD(WEEK, DATEDIFF(WEEK, 0, @DT), 0)
THEN
SUM(CASE WHEN EmailActivityType = 'OPEN' THEN 1 ELSE 0 END) END AS WeekTotalOpens
FROM EmailActivity
WHERE DATEPART(YEAR, [ActivityDate]) = DATEPART(YEAR, @DT)
GROUP BY EmailAddressID,emailaddress
Desired Output:
EmailAddressId EmailAddress WeekTotalOpens MonthTotalOpens etc. then WeekTotalClicks and so on....

SQL doesn't seem to like the sub-aggregate. What is the best way to approach?

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved