Hi All,
I have problem that I am trying to handle in a SQL Server 2000 stored procedure. This stored procedure returns a list of records where the count from a sub-query is greater than 3. In these returned records I need to assign a priority number to groups of the records. Basically every three records would get the same number, the next three would get the next number (incremented by 1), and so on.
Can I handle this as a stored procedure?
My stored procedure so far:
The fields in the table are:
FY - An integer
InitiativeID - An autoincrementing integer (PK)
PriorityOrder - Hopefully the output of the stored procedure
My output should look like this:
Thanks,
jbehrne
If at first you don't succeed, call in an airstrike. - Murphy's Laws of Combat Operations
I have problem that I am trying to handle in a SQL Server 2000 stored procedure. This stored procedure returns a list of records where the count from a sub-query is greater than 3. In these returned records I need to assign a priority number to groups of the records. Basically every three records would get the same number, the next three would get the next number (incremented by 1), and so on.
Can I handle this as a stored procedure?
My stored procedure so far:
Code:
ALTER PROCEDURE dbo.usp_Prioritization
@FY int)
AS
DECLARE @priorityOrder int
SELECT FY, InitiativeID FROM dbo.Initiatives
WHERE FY = @FY) AND EXISTS
(SELECT COUNT(FY) AS FYCount, FY
FROM dbo.Initiatives
GROUP BY FY
HAVING COUNT(FY) > 3))
RETURN
The fields in the table are:
FY - An integer
InitiativeID - An autoincrementing integer (PK)
PriorityOrder - Hopefully the output of the stored procedure
My output should look like this:
Code:
FY InitiativeID PriorityOrder (the generated field)
2010 1 1
2010 2 1
2010 3 1
2010 4 2
2010 5 2
2010 6 2
2010 7 3
2010 8 3
2010 9 3
2010 10 4
2010 11 4
2010 12 4
...
Thanks,
jbehrne
If at first you don't succeed, call in an airstrike. - Murphy's Laws of Combat Operations