December 8, 2003 at 7:03 am
Can I make my own aggregate function?
December 8, 2003 at 7:24 am
You mean extending the built-in SQL commands?
I don't think so, however you can always write your own function.
What do you want to do?
Frank
--
Frank Kalis
Microsoft SQL Server MVP
Webmaster: http://www.insidesql.org/blogs
My blog: http://www.insidesql.org/blogs/frankkalis/[/url]
December 9, 2003 at 10:22 am
Yes.
You can also create an aggregate column(s) in a table. This is good for reporting purposes as theres no need to do the calculations when the report is running.
-Isaiah
December 9, 2003 at 10:54 am
As far as I know, you can only write user-defined functions that are scalar or table-valued, not aggregate.
Edited by - chrisleonard on 12/09/2003 10:54:37 AM
December 9, 2003 at 12:41 pm
quote:
Yes.You can also create an aggregate column(s) in a table. This is good for reporting purposes as theres no need to do the calculations when the report is running.
I think you're on the wrong track.
He meant something like making his own SUM(), AVG()....functions.
Frank
--
Frank Kalis
Microsoft SQL Server MVP
Webmaster: http://www.insidesql.org/blogs
My blog: http://www.insidesql.org/blogs/frankkalis/[/url]
December 9, 2003 at 6:09 pm
Can you create aggregate calculated columns in a table? Like a running sum?
I didn't think it possible, except via code based on triggers.
A query could do it, for example:
create table TestSum (
id int identity primary key clustered,
numcol int,
sumcol int
)
update TestSum
set sumcol = (select sum(b.numcol)
from TestSum b
where b.id <= TestSum.id)
but do calculated columns allow queries?
A view should work:
SELECT TOP 100 PERCENT a.id, a.numcol, SUM(b.numcol) AS sumcol
FROM dbo.TestSum a INNER JOIN
dbo.TestSum b ON a.id >= b.id
GROUP BY a.id, a.numcol
ORDER BY a.id
Is there a better way to accomplish this?
Data: Easy to spill, hard to clean up!
December 10, 2003 at 2:24 pm
quote:
quote:
Yes.You can also create an aggregate column(s) in a table. This is good for reporting purposes as theres no need to do the calculations when the report is running.
I think you're on the wrong track.
He meant something like making his own SUM(), AVG()....functions.
Frank
I see, yes, you are correct. I dont think SQL can do this. You would have to do this with code.
-Isaiah
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply