Aggregate functions

  • Can I make my own aggregate function?

  • 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

    http://www.insidesql.de

    http://www.familienzirkus.de

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • 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

  • 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

  • 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

    http://www.insidesql.de

    http://www.familienzirkus.de

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • 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!

  • 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

    http://www.insidesql.de

    http://www.familienzirkus.de


    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