I am trying to loop through a sql select statement.
and on each row run a sendemail to the data from that row.
I copied this code from something else and I am not sure that I took too much and what can be removed.
I have something like this, but it's not 100% correct because the while loop is throwing an error.
declare csrIds cursor static for
while 1 = 1
fetch next from csrIds into @id
if @@FETCH_STATUS <> 0
select @email = bd.Email, @name = bd.FirstName
from TestEmail bd
where sentEmail<> 1
DECLARE @Sub nvarchar(MAX)
SET @Sub = 'this is a record that came through: ' + @email + ' and name of : ' + @name
@body_format= 'HTML',@recipients= @email ,@subject = 'Cash Receipts' ,