?
Solved

user defined aggregate function

Posted on 2004-04-05
3
Medium Priority
?
421 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 1000 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
I have a large data set and a SSIS package. How can I load this file in multi threading?
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Suggested Courses

764 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