Solved

user defined aggregate function

Posted on 2004-04-05
3
397 Views
Last Modified: 2008-03-17
I need to make my own aggregate function. I'm running sql server 2000, can someone give me an example of how to do this.

btw, this is what I'm trying to do:

given a list of numeric values ie (1,2,2,1,0,2) I need to return 0 if 0 occurs before 1, or 1 if 1 occurs before 0

0
Comment
Question by:gfody
3 Comments
 
LVL 4

Accepted Solution

by:
mikkelp earned 250 total points
ID: 10761818

You can't write your own aggregate function

check this: http://www.experts-exchange.com/Databases/Microsoft_SQL_Server/Q_20881703.html

I don't believe it's possible to write a function to take a variable number of parameters, but you could probably get around your problem by selecting the "index" of 0 and 1 and compare the two... ie

select case when .... then 1 else 0 end.

where "index" is defined by the sort-order of your query.
0
 
LVL 26

Expert Comment

by:Hilaire
ID: 10763673
Agree with mikkelp

Writing custom aggregate function will be possible with SQL Server 2005 (Yukon)

If you need more support, please post more details on what you want, the queries you already have, and we'll see what can be done

Hilaire
0
 
LVL 2

Author Comment

by:gfody
ID: 10972720
I have a very complicated set of tables for permissions based on the nested sets model. The routine for processing your permission records to determine whether or not you have access to something is a function that reads in all the permission records on your tree and recursively collapses them. I could do it all in sql if I could define an aggregate like the one in my first post.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question