Quantcast
Channel: ฟอรัม Getting started with SQL Server
Viewing all articles
Browse latest Browse all 8428

Status to Mail sent and Not sent

$
0
0

Hi,

    I have a list of records which contains to whom i should send a mail.Below is the screen shot and procedure which gives me the records.

Now i want a stored procedure , In below screenshot if 1st record means if the mail is sent  for 1st record it should mark as sent . and i should be left out with a records for which a mail is not sent.

From the below proc i have got these two records.

Please help me with the procedure.I am using SQL server 2008.

The mail sending process is all done through coldfusion. I just want to give a list of mails sent  and if sent it should mark as sent and should be left out with not sent mails.

     IF OBJECT_ID ('dbo.Mail_Send') IS NOT NULL
     DROP PROCEDURE dbo.Mail_Send
GO

CREATE  PROCEDURE [dbo].Mail_Send

(
@userid            int,
@weekEndDate       datetime,
@sessionUserID     int
)
AS
BEGIN
             IF OBJECT_ID ('tempdb..#Temp') IS NOT NULL
            BEGIN
                  DROP TABLE #temp
            END--IF
            CREATE TABLE  #Temp
                (            

 [Action]         varchar(50),
 UserID         int,
 LastName       varchar(50),
 FirstName      varchar(50),
 WeekEndDate    DateTime,
 Reason         Varchar(500),
 To_email       varchar(100),
 SessionUserID  int,
 MFirstName     varchar(50),
 MLastName      varchar(50), 
 )

    INSERT INTO #Temp 

SELECT 
            ts_ActionHistory_Action AS ACTION, ts_ActionHistory_tsOwner_usr_ID_FK AS UserID,lname AS LastName , fname AS FirstName,
            ts_ActionHistory_WeekEndingDate AS WeekEndDate,ts_ActionHistory_comments AS Reason ,email,mgr_id AS SessionUserID,SUPFIRSTNAME AS MFirstName,SUPLastName AS MLastName
            FROM tbl_timeSheet_ActionHistory TAH,  
                     (  
                              SELECT 
                                    ts_ActionHistory_WeekEndingDate as WeekEndingDate,
                                    MAX(ts_ActionHistory_ActionDate) AS actionDate ,
                                    ts_ActionHistory_tsOwner_usr_ID_FK AS userID 

                              FROM tbl_timeSheet_ActionHistory  
                              WHERE ts_ActionHistory_tsOwner_usr_ID_FK =@userid 
                              and ts_ActionHistory_WeekEndingDate = @weekEndDate 
                              and ts_ActionHistory_Action='Disapprove'
                              GROUP BY ts_ActionHistory_tsOwner_usr_ID_FK ,
                              ts_ActionHistory_WeekEndingDate 

                     )TAH1  
                     Inner join v_empSup AS A
                     ON TAH1.userID = A.usr_id 
                     WHERE   
                              TAH1.userID = TAH.ts_ActionHistory_tsOwner_usr_ID_FK  
                              AND TAH1.WeekEndingDate= TAH.ts_ActionHistory_WeekEndingDate
                              AND TAH.ts_ActionHistory_ActionDate  = TAH1.actionDate




   Insert into Mail ([Action],FirstName ,LastName ,WeekEndDate ,MFirstName ,MLastName ,Reason ,To_email ,From_email )
   Select
           [Action],
           FirstName ,
           LastName ,
           WeekEndDate ,
           MFirstName ,
           MLastName ,
           Reason,
           To_email,
           From_email =  (Select  email from v_empSup  where usr_id  = @sessionUserID  ) 
           from #Temp 

    --Select * from Mail                          
END

Thanks,

                                                                                                                                        

Deepa


Viewing all articles
Browse latest Browse all 8428

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>