| 
                
Please start any new threads on our new 
    site at https://forums.sqlteam.com.  We've got lots of great SQL Server
    experts to answer whatever question you can come up with. 
    
        | 
                
                    | 
                            
                                | Author | Topic |  
                                    | egghiStarting Member
 
 
                                        17 Posts | 
                                            
                                            |  Posted - 2006-10-16 : 13:30:36 
 |  
                                            | Hi,I have a trigger for a table which stores email information generated from an ACCESS form.  The trigger should send an auto email response to users who submitted an email to request for their password (we have forgetful users!).  There is something wrong with my trigger because the auto email is sent out with a blank body... I will appreciate any advice!Thank you!My trigger:CREATE TRIGGER tr_SendPassword ON PIPEmailFOR INSERTAS DECLARE @Password varchar(100)DECLARE @EmailAddress varchar(100)DECLARE @message varchar(100)IF (select count(*) from inserted) = 1BEGIN    IF exists (SELECT * FROM inserted    WHERE Subject = 'Forgot my password')    BEGIN         select @Password = 'We received an email request from you for your password.  Your password for SAR Search is: ' + UserRole.Password,             @EmailAddress = [User].Email         from UserRole         join inserted on UserRole.WindowsUser = inserted.WindowsUser         join [User] on [User].WindowsUser = UserRole.WindowsUser        exec master.dbo.xp_sendmail @recipients=@EmailAddress,             @subject='SAR Search password request',             @message=@Password    ENDEND |  |  
                                    | Michael Valentine JonesYak DBA Kernel (pronounced Colonel)
 
 
                                    7020 Posts | 
                                        
                                          |  Posted - 2006-10-16 : 14:07:00 
 |  
                                          | It is not a good idea to send email from a trigger.You should create a stored procedure to do this, and call that from your form.CODO ERGO SUM |  
                                          |  |  |  
                                    | egghiStarting Member
 
 
                                    17 Posts | 
                                        
                                          |  Posted - 2006-10-16 : 15:35:29 
 |  
                                          | Hi,I am not very good at writing stored procedure...  So far, I haveCREATE PROCEDURE s_AutoEmail ON PIPEmailASDECLARE @Password varchar(100)DECLARE @EmailAddress varchar(100)DECLARE @body varchar(1024)IF (select Subject from PIPEmail) = 'Forgot my password'BEGINSET @body = 'select @Password = 'We received an email request from you for your password. Your password for SAR Search is: ' + UserRole.Password,@EmailAddress = [User].Emailfrom UserRolejoin PIPEmail on UserRole.WindowsUser = PIPEmail.WindowsUserjoin [User] on [User].WindowsUser = UserRole.WindowsUser'exec master.dbo.xp_sendmail @recipients=@EmailAddress,@subject='SAR Search password request',@message=@bodyENDENDAlso, how do I add a statement to the stored procedure that will flag the record on PIPEmail table after an auto email response has been sent to user?Thank you! |  
                                          |  |  |  
                                    | Michael Valentine JonesYak DBA Kernel (pronounced Colonel)
 
 
                                    7020 Posts | 
                                        
                                          |  Posted - 2006-10-16 : 19:12:51 
 |  
                                          | You don't create s stored procedure on a table: CREATE PROCEDURE s_AutoEmail ON PIPEmailYou will need to make the user logon a parameter of the stored procedure, and pass that as a partameter to the procedure.CODO ERGO SUM |  
                                          |  |  |  
                                    | egghiStarting Member
 
 
                                    17 Posts | 
                                        
                                          |  Posted - 2006-10-17 : 13:36:07 
 |  
                                          | I see.  I will give it a try:)  Thank you! |  
                                          |  |  |  
                                |  |  |  |  |  |