I have a table with managers and their employess.
Column Manager has a manager, one to many times for each employee, like so:
Manager employee
Fred Wilma
Fred Pebbles
Fred Dino
Barney Betty
Barney BamBam
I need to set @employess ='Wilma, Pebbles, Rocky' the first time fior Fred and next for Manager Barney the
@employess = 'Betty, BamBam'
I want to email them each Manager and have the 'body' of the email all his employess, so Fred gets an email with 'Wilma, Pebbles, Rocky'
and Barney get an email with 'Betty, BamBam' in the body. I can do the email part, just thaving trouble shoving in more than one item into a variable
DougP
Column Manager has a manager, one to many times for each employee, like so:
Manager employee
Fred Wilma
Fred Pebbles
Fred Dino
Barney Betty
Barney BamBam
I need to set @employess ='Wilma, Pebbles, Rocky' the first time fior Fred and next for Manager Barney the
@employess = 'Betty, BamBam'
I want to email them each Manager and have the 'body' of the email all his employess, so Fred gets an email with 'Wilma, Pebbles, Rocky'
and Barney get an email with 'Betty, BamBam' in the body. I can do the email part, just thaving trouble shoving in more than one item into a variable
Code:
DECLARE @Email nvarchar(150)
DECLARE @strSubject nvarchar(200)
DECLARE @strBody nvarchar(max)
DECLARE @Name nvarchar(max)
DECLARE mycursor CURSOR LOCAL FAST_FORWARD FOR
Select Distinct Email from SOWEmailManagerListResource
OPEN mycursor
WHILE 1 = 1
BEGIN
FETCH NEXT FROM mycursor
INTO @Email
IF @@FETCH_STATUS <> 0
break
Else
Begin
Set @employee = (Select (LastName +', '+ FirstName) as employee from SOWEmailManagerListResource
Where Email= @Email)
-- need to set @employee to each person under them.
end
end
CLOSE mycursor
DEALLOCATE mycursor
DougP