set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GOALTER PROCEDURE [dbo].[usp_SendEmailJobUsed]
-- Add the parameters for the stored procedure here
AS
BEGIN SET NOCOUNT ON; DECLARE @to nvarchar(1000),@subject nvarchar(100),@textBody varchar(MAX),@htmlBody varchar(MAX), @id int, @bcc NVARCHAR(50),@from NVARCHAR(100),@emailID UNIQUEIDENTIFIER
Declare @object int,@hr int,@serverHost nvarchar(100),@userName nvarchar(100), @passWord nvarchar(50),@useSSL int,@ssl nvarchar(10),@useServerCredentials int
DECLARE @campaignID INT,@sendTime DATETIME,@EmailCount INT,@CampaignStatus VARCHAR(50)

--select @sendTime = MIN(SendTime) FROM [EmailInfo]
SELECT @sendTime = (
  SELECT MIN(SendTime) FROM [EmailInfo]
)

IF @sendTime <= Getdate()
BEGIN
declare cur_email cursor FOR
  SELECT [EmailInfo].[emailInfoID],[EmailInfo].[recipients],[EmailInfo].[EmailSubject],[EmailInfo].[TextBody],
     [EmailInfo].[HtmlBody],'('+[EmailInfo].[FromName]+')'+[EmailInfo].[FromEmail] AS [FROM],[EmailInfo].[BccEmail]--,EmailID,[EmailInfo].[CampaignId]
    FROM [EmailInfo] 
    WHERE [EmailInfo].[SendTime]=@sendTime
    
OPEN cur_email
FETCH NEXT FROM cur_email INTO @id,@to,@subject,@textbody,@htmlBody,@from,@bcc

WHILE @@fetch_status=0 --process success
BEGIN
select @serverHost = serverHost,@userName = serverUserName,@passWord = serverPassWord,
       @useSSL = useServerSSL,@useServerCredentials = useServerCredentials 
        from dbo.EmailConfig          if @useSSL=1
begin
set @ssl='true'
end
else
begin
set @ssl='false'
end
EXEC @hr = sp_OACreate 'CDO.Message', @object OUT EXEC @hr = sp_OASetProperty @object, 'Configuration.fields("http://schemas.microsoft.com/cdo/configuration/sendusing").Value','2'
EXEC @hr = sp_OASetProperty @object, 'Configuration.fields("http://schemas.microsoft.com/cdo/configuration/smtpserver").Value', @serverHost
EXEC @hr = sp_OASetProperty @object, 'Configuration.fields("http://schemas.microsoft.com/cdo/configuration/smtpusessl").Value', @ssl if @useServerCredentials=1
begin
EXEC @hr = sp_OASetProperty @object, 'Configuration.fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate").Value','1'
EXEC @hr = sp_OASetProperty @object, 'Configuration.fields("http://schemas.microsoft.com/cdo/configuration/sendusername").Value',@userName
EXEC @hr = sp_OASetProperty @object, 'Configuration.fields("http://schemas.microsoft.com/cdo/configuration/sendpassword").Value',@passWord
end EXEC @hr = sp_OAMethod @object, 'Configuration.Fields.Update', null
EXEC @hr = sp_OASetProperty @object, 'To', @to
EXEC @hr = sp_OASetProperty @object, 'From', @from
EXEC @hr = sp_OASetProperty @object, 'Subject', @subject
IF @bcc<>''
begin
EXEC @hr = sp_OASetProperty @object, 'Bcc', @bcc
END
EXEC @hr = sp_OASetProperty @object, 'HTMLBody', @htmlBody
EXEC @hr = sp_OASetProperty @object, 'TextBody', @textBody
EXEC @hr = sp_OAMethod @object, 'Send', NULL EXEC @hr = sp_OADestroy @object
--UPDATE dbo.EmailList SET LastestSendTime=GETDATE(),SentTimes=SentTimes+1 WHERE emailID=@emailID
      DELETE FROM [EmailInfo] WHERE [emailInfoID] = @id

FETCH NEXT FROM cur_email INTO @id,@to,@subject,@textbody,@htmlBody,@from,@bcc
END
close cur_email
DEALLOCATE cur_email
    
    
END
END这种问题怎么解决呢?