Hi,
Thanks for the reply - I've since tried using that method - and in query analyser it works fine and outputs the results I need - but Im having trouble using this query to output the results table in the stored proc as I need to send it as a html email -
I thought this might work but it doesnt, do you know how I can use this query in an sp and send the results via cdosysmail ?
SET @MailBody='<html>
<head>
<style type="text/css">
<!--
body,td,th {
font-family: Verdana;
color:#7d6f62;
}
body {background-color:#f5f4f1;
}
-->
</style></head>
<body><p><b>Survey start count</b></p><table border="1" cellpadding"0" cellspacing"0">
<tr><td><b>Project name</b></td><td><b>Points rewards</b></td></tr>'
SELECT '<tr><td>' + projectname + '</td><td>' + sum(pointsrewards)+ '</td></tr>' from usersurveyhistory group by projectname
SET @MailBody=@MailBody + '</table><br><hr size="1"></body></html>'
SET @MailTo='[email protected]'
-- get next record
FETCH NEXT FROM c1 INTO @proname END
-- close and shut down the cursor
CLOSE c1 DEALLOCATE c1
exec dbo.sp_send_cdosysmail
@From = @MailFrom,
@To =@MailTo,
@bcc ='[email protected]',
@Subject =@MailSubject,
@Body =@MailBody
end
GO
Enter your message below
Sign in or Join us (it's free).