Solved

user defined aggregate function

Posted on 2004-04-05
3
376 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

706 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now