Patent ID: 7181449

Claim:
A method of applying a scalar function across a varying number of records in a relational database management system having SQL capabilities, comprising the steps of: a) determining a last row in a group of rows by the set of SQL commands comprising: i) With Ordered_Rows as (SELECT group 1 , column 1 , column 2 , column 3 , count(*) over (partition by group 1 ) as group_count order by group 1 ) ii) Calculate_Aggregate_Rows as (SELECT group 1 , SCALAR_UDF (group 1 , column 1 , column 2 , column 3 , group_count) as Aggregate_Value From Ordered_Rows) iii) SELECT group 1 , Aggregate_Value From Calculate_Aggregate-Rows Where Aggregate_Value is NOT NULL to thereby return a single value for each group of rows across multiple columns/expressions; b) sorting said rows and passing the sorted rows to a scalar function, said scalar function adapted to accept each row and store the accepted rows in a temporary file space; c) when a last row is encountered, calculating an aggregate value using all of the rows in the group; and d) applying a filter on said rows so that only a row with said aggregate value is returned.