Hello all,Was hoping to get a little help on this project I have been tasked to do. Its been 10+ years since I even messed with a cursor but for the life of me this one has got me. First set of code is the HTML mock up of what this will be spitting out into someones email. Second code is the SP as it sits now. Currently it seems to do an endless loop and not creating the html. This is on a 2000 machine that will be moved to 2012 in a couple of months. Feel free to mock or show me how horrible I am. Long as I end up figuring this one out.HTML<html>  <body>    <br />    <br />    <font face="verdana" size="2">The board has just been updated with the following values:</font>    <br />	<br />	<font face="verdana" size="2"><b>Campus A</b></font>    <table>      <tr>		<td>8-2014</td>        <td>Metric A:</td>        <td>1</td>      </tr>      <tr>		<td>8-2014</td>        <td>Metric B:</td>        <td>5</td>      </tr>      <tr>		<td>8-2014</td>        <td>Metric C:</td>        <td>3</td>      </tr>    </table>    <br />    <br />	<font face="verdana" size="2"><b>Campus B</b></font>    <table>      <tr>		<td>8-2014</td>        <td>Metric A:</td>        <td>3</td>      </tr>      <tr>		<td>8-2014</td>        <td>Metric B:</td>        <td>2</td>      </tr>      <tr>		<td>8-2014</td>        <td>Metric C:</td>        <td>4</td>      </tr>    </table>    <br />    <br />    <font face="verdana" size="2">    <a href="https://www.website.net/login.asp">Click here to login.</a>    <br />    <br />Please contact the us should you have any questions.    <br />    <br />Phone: 555-555-5555   Email:     <a href="mailto:help@website.net">help@website.net</a>    <br />    <br />Thank you.</font>  </body></html>
TSQLBEGIN	-- eMail Variables --	DECLARE @email_subject VARCHAR(1000),		@email_header VARCHAR(8000),		@email_body VARCHAR(8000),		@email_footer VARCHAR(8000),		@email_complete VARCHAR(8000),		@vTotalProviderCount INT,		@vTotalCampusCount INT,		@vTotalMetricCount INT,		@vProviderCount INT,		@vCampusCount INT,		@vProviderNum VARCHAR(20),		@vProviderName VARCHAR(80),		@vCampus VARCHAR(500),		@vMetricCount INT,		@intMessageID INT,		@vDate_Label VARCHAR(10),		@vMetricName VARCHAR(60),		@vMetricValue VARCHAR(60)	-- Select * From test_email	SELECT @email_subject = Substring(Db_name(), 5, Len(Db_name()) - 4)	SET @email_header = '<html>  <body>    <br />    <br />    <font face="verdana" size="2">The dashboard has just been updated with the following values for your metrics:</font>    <br />    <br />'	SET @email_header = '<br />    <br />    <font face="verdana" size="2">    <a href="https://www.website.net/login.asp">Click here to login.</a>    <br />    <br />Please contact the PSR support desk should you have any questions.    <br />    <br />Phone: 555-555-5555   Email:     <a href="mailto:help@website.net">help@website.net</a>    <br />    <br />Thank you.</font>  </body></html>'	SET @vTotalProviderCount = (			SELECT count(DISTINCT provider_num)			FROM test_email -- This need to change to temp table.			)	DECLARE cur_provider CURSOR	FOR	SELECT DISTINCT provider_num	FROM test_email -- This need to change to temp table.	OPEN cur_provider	SET @vProviderCount = 0	WHILE @vProviderCount < @vTotalProviderCount	BEGIN		FETCH NEXT		FROM cur_provider		INTO @vProviderNum		------------------------------------		SET @vTotalCampusCount = (				SELECT count(DISTINCT campus)				FROM test_email -- This need to change to temp table.				WHERE provider_num = @vProviderNum				)		DECLARE cur_campus CURSOR		FOR		SELECT DISTINCT campus		FROM test_email -- This need to change to temp table.		WHERE provider_num = @vProviderNum		OPEN cur_campus		SET @vCampusCount = 0		WHILE @vCampusCount < @vTotalCampusCount		BEGIN			FETCH NEXT			FROM cur_campus			INTO @vCampus			-------------------------------			--set = N'<font face="verdana" size="2"><b>'+ltrim(rtrim(@vCampus))+'</b></font>'			SET @vTotalMetricCount = (					SELECT count(*)					FROM test_email -- This need to change to temp table.					WHERE provider_num = @vProviderNum						AND campus = @vCampus					)			DECLARE cur_metric_CT CURSOR			FOR			SELECT date_label,				dial_label,				metricvalue,				provider_num,				last_name + ', ' + first_name			FROM test_email -- This need to change to temp table.			WHERE provider_num = @vProviderNum				AND campus = @vCampus			OPEN cur_metric_CT			SET @vMetricCount = 0			SET @email_body = N'<font face="verdana" size="2"><b>' + ltrim(rtrim(@vCampus)) + '</b></font>'			FETCH NEXT			FROM cur_metric_CT			INTO @vDate_Label,				@vMetricName,				@vMetricValue,				@vProviderNum,				@vProviderName			WHILE @vMetricCount < @vTotalMetricCount /*loop for Metrics*/			BEGIN				SET @email_body = @email_body + N'<table><tr>'				SET @email_body = @email_body + N'<td>' + @vDate_Label + '<td>'				SET @email_body = @email_body + N'<td>' + @vMetricName + '<td>'				SET @email_body = @email_body + N'<td>' + @vMetricValue + '<td>'				SET @email_body = @email_body + N'</tr></table>'				FETCH NEXT				FROM cur_metric_CT				INTO @vDate_Label,					@vMetricName,					@vMetricValue,					@vProviderNum				SET @vMetricCount = @vMetricCount + 1			END			SET @email_complete = @email_header + @email_body + @email_footer			CLOSE cur_metrics_CT			DEALLOCATE cur_metrics_CT		END		CLOSE cur_provider		DEALLOCATE cur_provider	ENDEND