Solved

user defined aggregate function

Posted on 2004-04-05
3
410 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
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.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how the fundamental information of how to create a table.

726 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