0

任何人都可以帮助以下存储过程吗?我收到错误

'@profile_name' 附近的语法不正确” SELECT distinct(EmailAddress) as RECIPIENTS, @body = Replace(@bodypre, "$Approver", Forename) FROM [STAS].[dbo].[NotifictationEmailID_View]

在查询中

SELECT distinct(EmailAddress) as RECIPIENTS,
      @body = Replace(@bodypre, "$Approver", Forename) 
FROM [STAS].[dbo].[NotifictationEmailID_View]   

这是此存储过程的一部分:

ALTER proc [dbo].[test]
as
begin
DECLARE @subject VARCHAR(500)
Declare @bodypre varchar(5000)
DECLARE @ProgramName VARCHAR(50)
DECLARE @FirstName VARCHAR(50)
DECLARE @body VARCHAR(5000)
DECLARE @email VARCHAR(500)
declare @recipients VARCHAR(5000)
DECLARE @CurrentRec AS INT
DECLARE @RecCount AS INT
Declare @emailStop  as int
SET @CurrentRec = 1
SET @RecCount = 0

select @subject=EmailMessageSubject,
        @bodypre = EmailMessageBody,
        @emailStop = EmailStop_Flag
from STAS.dbo.MC_STAS_EmailMessage where TimeSheetStatusID = 3 

SELECT @RecCount = COUNT(EmailAddress) FROM [STAS].[dbo].[NotifictationEmailID_View] 
if (@emailStop <> 1 AND @RecCount > 0)
    WHILE @RecCount >= @CurrentRec
    begin   
    EXEC msdb.dbo.sp_send_dbmail
    SELECT distinct(EmailAddress) as RECIPIENTS ,@body =Replace(@bodypre,"$Approver",Forename) from [STAS].[dbo].[NotifictationEmailID_View]                    
        @profile_name = "STAS Email User",
        @recipients = @RECIPIENTS,
        @subject = @SUBJECT,
        @body = @body

    SET @CurrentRec = @CurrentRec + 1
end
end

谢谢,

4

1 回答 1

0

试试这个:

SELECT DISTINCT 
      EmailAddress as RECIPIENTS,
      @body = Replace(@bodypre, "$Approver", Forename) 
FROM [STAS].[dbo].[NotifictationEmailID_View]   

DISTINCT不是一个可以像以前那样调用的函数——它是一个 SQL 关键字。

于 2012-05-03T15:29:19.603 回答