Hello All,
Right I've fixed this bit:
Hello @staff --My @staff variable is not being entered here
by changing to:
OPEN email_cursor
FETCH NEXT FROM email_cursor
INTO @toemail, @staff
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT @toemail
SET @body = '<html><body>Hello ' + @staff + '</body></html>'
EXEC msdb.dbo.sp_send_dbmail
@recipients = @toemail,
@subject = 'Jobs Logged Today",
@body_format = 'HTML',
@body = @body,
@execute_query_database = 'mydb',
@query = 'SELECT "<table><tr><td><a href=www.mydomain/jobs.php?staff_code="+ RTRIM([Staff Code]) +"&job_id="+ RTRIM([ID]) +">View Job ID: "+ RTRIM([ID]) +"</a></td></tr></table>"
FROM jobs
WHERE ([staff code] = "@staff")'
FETCH NEXT FROM email_cursor
INTO @toemail, @staff
END
CLOSE email_cursor
DEALLOCATE email_cursor
But I still can't pass the variable to the query???
Also How do I get more HTML after the results have been displayed in the email?
Sorry for all the q's...
Many Thanks