I'm using SQL 7.0. Were I'm using this is in a job. I'm having trouble getting the variable @assignedto as part of the @query= statement.

DECLARE @email varchar(50)
DECLARE @assignedto varchar(6)
DECLARE tnames_cursor CURSOR
FOR
SELECT (SELECT RTRIM(intranet.dbo.employee.email) FROM intranet.dbo.employee WHERE intranet.dbo.employee.employeeid = intranet.dbo.bugs.assignedto) as assignedtoemail, intranet.dbo.bugs.assignedto
FROM intranet.dbo.bugs, intranet.dbo.description, intranet.dbo.steps
WHERE intranet.dbo.bugs.id = intranet.dbo.description.refid AND intranet.dbo.description.reftext = 'bugs' AND
intranet.dbo.bugs.id = intranet.dbo.steps.refid AND intranet.dbo.steps.reftext = 'bugs' AND
getdate() > DATEADD(ww, 2, intranet.dbo.bugs.updatetime) AND
getdate() > DATEADD(ww, 2, intranet.dbo.description.dated) AND
getdate() > DATEADD(ww, 2, intranet.dbo.steps.dated) AND
intranet.dbo.bugs.status <> '1'
GROUP BY intranet.dbo.bugs.assignedto
OPEN tnames_cursor
FETCH NEXT FROM tnames_cursor INTO @email, @assignedto
WHILE (@@FETCH_STATUS <> -1)
BEGIN
EXEC master.dbo.xp_sendmail @recipients = @email,
@no_header = 'TRUE',
@query = 'SELECT (" Bug ID -- " +
CONVERT(varchar, intranet.dbo.bugs.id) + " -- http://netmapintranet/development/bu...t3.asp?bugsid=";
+ CONVERT(varchar, intranet.dbo.bugs.id) + "&applicationid=" + CONVERT(varchar, intranet.dbo.bugs.applicationid) + "&reportedby=" + CONVERT(varchar, intranet.dbo.bugs.reportedby) + "&srtval=bugs.severity")
from intranet.dbo.bugs, intranet.dbo.description, intranet.dbo.steps
WHERE (intranet.dbo.bugs.id = intranet.dbo.description.refid AND intranet.dbo.description.reftext = "bugs" AND
intranet.dbo.bugs.id = intranet.dbo.steps.refid AND intranet.dbo.steps.reftext = "bugs" AND
getdate() > DATEADD(ww, 2, intranet.dbo.bugs.updatetime) AND
getdate() > DATEADD(ww, 2, intranet.dbo.description.dated) AND
getdate() > DATEADD(ww, 2, intranet.dbo.steps.dated) AND
intranet.dbo.bugs.status <> "1") AND
intranet.dbo.bugs.assignedto = @assignedto>',
@subject = 'Bug(s) Notice.',
@message = 'The following bug(s) have not had any activity in the last two weeks.',
@width = 1000
FETCH NEXT FROM tnames_cursor INTO @email, @assignedto
END
CLOSE tnames_cursor
DEALLOCATE tnames_cursor