using Rollup in SQL

Hi,

I am trying to use ROLLUP, but I am getting

Msg 195, Level 15, State 10, Line 17
'ROLLUP' is not a recognized built-in function name.

any ideas?  I have SQL 2014

thanks
mcrmgAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Nitin SontakkeDeveloperCommented:
May be you should have posted here the query you are trying out.
0
mcrmgAuthor Commented:
please have a look. thanks

				SELECT      username, [Call],[Contact],[Deadline]
							, [Call],[Contact],[Deadline] AS Total

 

				FROM 
				(
					SELECT username, Activity  FROM table1 WHERE CONVERT(varchar(12),ActivityDate, 101) = dateadd(day,datediff(day,1,getDate()),0)

				) src
				PIVOT
				(
					COUNT(Activity)  for Activity in ([Call],[Contact],[Deadline])
				) piv

				ORDER BY ROLLUP(username)

Open in new window

0
mcrmgAuthor Commented:
I think  I have found the problem, but still need ee's help.
It is "GROUP BY ROLLUP" not ORDER BY ROLLUP

But I am still not getting the preferred result. any ideas? thanks
0
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

Olaf DoschkeSoftware DeveloperCommented:
The syntax for a roll-up grouping is GROUP BY col1, col2,... ROLLUP.

It doesn't really make sense when grouping by just one column.
Here's an explanation of how it works: https://blog.sqlauthority.com/2010/02/24/sql-server-introduction-to-rollup-clause/

Are you perhaps looking for something else?

Bye, Olaf.
0
mcrmgAuthor Commented:
Thanks for the reply. I am trying to add "total" horizontally and vertically. The horizontal total works fine. It is the vertical total giving me the problem. thanks
0
Olaf DoschkeSoftware DeveloperCommented:
Rollup is not about that. Rollup is giving you aggregation on many levels at the same time, e.g., year, quarters, and months, without doing several queries and unioning the results. But the different levels of aggregation each are in their respective rows.

If by vertical summing you mean summing columns of the same row? Simply write out the sum col1+col2+col3...

When you can, start with the core data, eg (datetime, value) and go from there with a little pivoting. Take a look at the accepted solution example building monthly, quarterly and YTD values within a result row (vertically): https://www.experts-exchange.com/questions/28963238/SQL-sum-months-quarter-YTD.html

Oh, and the principle applies to other major dimensions, too, not only time. But it's a typical problem. You could also normally solve that on the level of reporting, creating a spreadsheet or such. You don't have to solve the layout of data in SQL, it's not the major strength of SQL.

Bye, Olaf.
0
mcrmgAuthor Commented:
Thank you for the information. I am actually looking for the sum of the same column from different rows. Any directions? thanks
0
Olaf DoschkeSoftware DeveloperCommented:
Well, at this stage it would really be helpful, if you could just write out a sample of data you have and result you want.

Summation of same column is simply a SUM() with GROUP BY, this needs no rollup at all.
Also notice, in the solution I linked to, all result amounts come from one original column only.

Bye, Olaf.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mcrmgAuthor Commented:
thank you
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.