I have a cursor and I want to check the value in the variables before I can set the values (managers assistant email), Can I use a while loop inside the cursor, then build the email message using the variables.and a bit of hardcoded text, Can I please get help with the syntax OPEN C_BirthdayReminder (the cursor Name) FETCH NEXT FROM C_BirthdayReminder INTO @ManagerID,@ManagerLoginName,@EmployeeID, @LoginName, @ClientID, @Sex WHILE @@FETCH_STATUS = 0 BEGIN SET @ManagerID = ReminderData.ManagerID SET @ManagerLoginName = ReminderData.ManagerLoginName + '@
domian.co.za;' WHILE @ManagerID = ReminderData.ManagerID (Can I do this?? Check so that I can load the Assistant details) BEGIN IF @EmployeeID != ReminderData.EmployeeID SET @EmployeeID = ReminderData.EmployeeID SET @LoginName = ReminderData.LoginName + '@
domain.co.za;' END IF IF @ClientID != ClientID Begin IF Sex = 3 Begin SET @Gender = 'She' End IF Sex = 2 begin SET @Gender = 'he' End SET @Clientname = ReminderData.Clientname SET @Birthdate = ReminderData,Birthdate SET @Age = ReminderData.Age SET Emailbody = 'It will be the birthday of' + '' + @Clientname + '' + 'on' + '' + @Birthdate + '' + '.' END --IF END --END Inner while Loop(@ManagerID = ClientData.ManagerID ) END -- END Ounter while FETCH NEXT FROM C_BirthdayReminder INTO @ManagerID,@ManagerLoginName,@EmployeeID, @LoginName, @ClientID, @Sex END CLOSE C_BirthdayReminder DEALLOCATE C_BirthdayReminder
Short answer, no! Long answer,I guess you are still trying to convert your c# code. I would create a procedure that takes a table parameter and creat the cursor of the table parameter ordered by manager Id, loop the cursor to create the strings for each record and send the mail when manager Id changes. To do that you need to store the manager_I'd in a second variable and check when the cursor variable changes.
Why not import all of the client details into a CRM system (Outlook/Exchange if you have no other) and then fix a reminder on each contact for the day or so before their birthday that gets your member of staff to take the necessary action. You can use you dev skills to write the code to create a recurring reminder for each contact that is their birthday date and its all done in a system that is design for this sort of thing. Even automating the email from Exchange would make sense.