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?
 
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
 
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
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
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
 
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
 
mcrmgAuthor Commented:
thank you
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.