|
Cursor help
I need to make a cursor to grab email addresses. Where an queueID is set to an email address and when the queueID is triggered/ matched it pulls the email address.
I did have a normal query that pulled down one email address. But some emails are assigned to multiple ID and some ID's have multiple emails assigned to it.
Here is the query I had at first:
Select emailAddress
From queueNotification
Where queueId = WORKITEM(workitem_assigned_to_worker_id)
AND (GetDate() Between ticketStartDate AND ticketEndDate
OR ticketEndDate = NULL)
Workitem() is the stntax from the system.
So I started making a stored procedure with a cursor in it so grab each email address that was assigned to that particular ID. So it would go through each orw at a time and put each email address into one long string and then send the emails out. But I'm having trouble.
Here is the Proc.:
Alter Procedure NotificationQueueEmail
(
@queueId int
)
As
Begin
Declare @emailAddress varchar (255)
Declare cursorQN_Email Cursor For
Select emailAddress
From queueNotification
Where queueId = @queueId -- took out WORKITEM(workitem_assigned_to_worker_id) and used the paramter @queueId
AND (GetDate() Between ticketStartDate AND ticketEndDate
OR ticketEndDate = NULL)
Open cursorQN_Email
--Performs the first fetch
Fetch Next From cursorQN_Email
Into @emailAddress
--Check ti see if there are anymore rows to fetch
While @@Fetch_Status = 0
Begin
Print @emailAddress + ';'
--Is executed as long as the previous fetch succeeds
Fetch Next From cursoreQN_Email
Into @emailAddress
End
Close cursorQN_Email
Deallocate cursorQN_Email
End
GO
Then I have this/// HDQUERY[[EXEC Altiris_Incidents.dbo.NotificationQueueEmail]] /// in the TO: section of the email address in the Notification rules.
I don't know if my paramters are the correct ones. Same with what variables I declared before the cursor.
Any help would be greatly apppreciated
|