gpt4 book ai didi

SQL Server 邮件变量的使用

转载 作者:行者123 更新时间:2023-12-02 09:08:58 25 4
gpt4 key购买 nike

我想在 SQL Server 上使用发送邮件实用程序,其中收件人变量 (@recipients) 应采用格式化字符串作为值。我想在下面展示一个例子:

EXEC msdb.dbo.sp_send_dbmail  
@profile_name = 'Mail Profile',
@recipients = Right('domain/<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="82f7f1e7f0c2e1edeff2e3ecfbace1edef" rel="noreferrer noopener nofollow">[email protected]</a>',
CHARINDEX('/',reverse('domain/<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e590968097a5868a8895848b9ccb868a88" rel="noreferrer noopener nofollow">[email protected]</a>'))-1),
@body = 'TEST MESSAGE',
@subject = 'Automated Success Message'

但是当我执行上面的语句时,出现错误消息:关键字Right附近的语法不正确

最佳答案

您不能将表达式作为参数传递给 am SP。您必须传递文字值或变量。您需要首先声明一个变量,设置它的值,然后将其作为参数传递:

DECLARE @recipients nvarchar(255);
SET @recipients = RIGHT('domain/<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="394c4a5c4b795a565449585740175a5654" rel="noreferrer noopener nofollow">[email protected]</a>', CHARINDEX('/', REVERSE('domain/<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="97e2e4f2e5d7f4f8fae7f6f9eeb9f4f8fa" rel="noreferrer noopener nofollow">[email protected]</a>')) - 1);

EXEC msdb.dbo.sp_send_dbmail @profile_name = 'Mail Profile',
@recipients = @recipients,
@body = 'TEST MESSAGE',
@subject = 'Automated Success Message';

关于SQL Server 邮件变量的使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54824188/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com