I am new to developing as will be evident from this post. Your help will be greatly appreciated.
I am developing an intranet for our company using ASP.NET with a SQL backend. I am currently working on a suggestion box form.
I would like to have an email sent to specific persons when a new entry is made in the suggestion table. I have been able to configure the trigger and generate the email (This was easy). Formatting the email has proven more difficult to resolve.
The format I would like is somewhat as follows:
F_NAME L_NAME submitted the following suggestion:
IDEA
BENEFIT
APPROVE | DECLINE
The items in RED are columns in the table and the Blue Underlines are hyperlinks to change the Status column in the table.
How can I generate the email to contain the data from the inserted record and in the above format.
Being new at this I only now how to send a static email advising that the entry has been made.
Any help creating the dynamic email form for this trigger will be greatly appreciated.
Lastly, what books are most helpful for SQL, ASP.NET, and VBScript referencing and examples
Thanks

Email Trigger in SQL 2005
EK4527
StevePee
DROP
TABLE ProposedNamesCREATE
TABLE ProposedNames(
ProposedNameId
INT IDENTITY(1,1) PRIMARY KEY,Firstname
VARCHAR(100),Lastname
VARCHAR(100),Accepted
BIT)
CREATE
TRIGGER INS_ProposedNamesON
ProposedNamesFOR
INSERTAS
BEGIN
SET
NOCOUNT ONDECLARE
@SomeHTMLText NVARCHAR(MAX)DECLARE
@RowCount INTDECLARE
@COUNTER INTSET
@Counter = 1CREATE
TABLE #Names(
Counted
INT IDENTITY(1,1),ProposedNameId
INT,Firstname
VARCHAR(100),Lastname
VARCHAR(100),)
INSERT
INTO #Names(
ProposedNameId
,Firstname
,Lastname
)
SELECT
ProposedNameId
,Firstname
,Lastname
FROM
INSERTEDSET
@ROWCOUNT = @@ROWCOUNTWHILE
@ROWCOUNT >= @CounterBEGIN
SEt @SomeHTMLText = '' SELECT @SomeHTMLText = '<HTML><BODY>' + 'The following names were proposed<br><br>' +@SomeHTMLText
+ 'FirstName: ' + Firstname + '<br><br>' + 'LastName: ' + Lastname + '<br><br>' + '<a href="http://www.someserver.com/Page.aspx Action=Accept&ID=' + CAST(ProposedNameId AS VARCHAR(10)) + '"> I Accept</a> | ' + '<a href="http://www.someserver.com/Page.aspx Action=Decline&ID=' + CAST(ProposedNameId AS VARCHAR(10)) + '"> I Decline</a>' + '</BODY></HTML>'FROM
#Names WHERE Counted = @CounterEXEC msdb..sp_send_dbmail
@recipients= 'TheRecipient@domain.com',
@subject
= 'Its up to you',@body
= @SomeHTMLText,@body_format
= 'HTML'SET
@Counter = @Counter +1END
DROP
TABLE #NamesEND
GO
--Try it:
INSERT
INTO ProposedNames(
Firstname,LastName)VALUES
('Jens', 'Susmeyer')HTH, Jens Suessmeyer.
---
http://www.sqlserver2005.de
---
Peter Scheffel
I wish to thank Jens Suessmeyer for the helpful infomraiton. Although the information provided did not fully resolve my issue the information provided me with enough knowledge to research and discover the solutions provided below.
I have created two triggers. The first trigger sends and e-mail message to the person in charge of reviewing the submission from the web form. The second trigger sends a confirmation e-mail to the person whom submitted the suggestion.
CREATE
Trigger [triggername]on
[tablename]for
insertas
declare
@text varchar(max)declare
@name varchar(max)declare
@idea varchar(max)declare
@benefit varchar(max)set
@text = ''set
@name = ''set
@idea = ''set
@benefit = ''select
@name = firstname + ' ' + lastname, @idea = idea, @benefit = benefitfrom
tablenamewhere
id = ident_current('tablename')set
@text = '<html><body>' + 'The following Bright Idea was submitted by ' +@name
+ ':<p>' + '<b>Idea: </b>' + @idea + '<p>' + '<b>Benefit: </b>' +@benefit
+ '<p>' + 'Please reveiw this idea as soon as possible.' +'</body></html>'
exec
msdb.dbo.sp_send_dbmail@profile_name
= 'profilename',@recipients
= 'recipientemailaddress',@subject
= 'New Bright Idea Submitted',@body
= @text,@body_format
= 'HTML'CREATE
Trigger [triggername]on
[tablename]for
insertas
declare
@text varchar(max)declare
@name varchar(max)declare
@idea varchar(max)declare
@benefit varchar(max)declare
@email varchar(max)set
@text = ''set
@name = ''set
@idea = ''set
@benefit = ''set
@email = ''select
@name = name, @idea = idea, @benefit = benefit, @email = emailfrom
tablenamewhere
id = ident_current('tablename')set
@text = '<html><body>' + @name + ',<p>Thank you for submitting your idea ' +'using our web based service. Your suggestion has been received and will be reveiwed '
+'by our management staff in the next couple of weeks.<p>Below is a copy of the idea '
+'we received from you:<p>'
+ '<b>Idea: </b>' + @idea +'<p><b>Benefit: </b>'
+ @benefit + '<p>Once again we would like to thank you for ' +'submitting your idea.'
+'</body></html>'
exec
msdb.dbo.sp_send_dbmail@profile_name
= 'profilename',@recipients
= @email,@subject
= 'New Bright Idea Submitted',@body
= @text,@body_format
= 'HTML'