Solved

user defined aggregate function

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

688 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