--创建测试表 use Fly Go IF OBJECT_ID('test') IS NOT NULL DROP TABLE test CREATE TABLE test( Id i
--创建测试表
use Fly
Go
IF OBJECT_ID('test') IS NOT NULL
DROP TABLE test
CREATE TABLE test(
Id int IDENTITY(1,1) NOT NULL,
Name varchar(50) NULL,
Judge char(1) NULL,
Mail varchar(50) NULL
)
GO
--插入测试数据
INSERT INTO test (
Name ,Judge ,Mail)
SELECT '张三','Y','100@qq.com' UNION ALL
SELECT '李四','Y','101@qq.com' UNioN ALL
SELECT '王五','N','102@qq.com'
GO
SELECT * FROM test
--查询多行合并
DECLARE
@Maliaddress varchar(8000)
set @Maliaddress = '''' + STUFF((SELECT ';' + Mail FROM test WHERE Judge in ('Y') FOR xml path('')),1,1,'') + ''''
select @Maliaddress as 'MailAddress'
exec msdb.dbo.sp_send_dbmail
@profile_name = 'Fly_Huang',
@recipients = @Maliaddress,
@subject = 'Test电子邮件的主题',
@body = 'Test电子邮件的正文',
@body_fORMat = 'html'
--结束END--
本文标题: Sql 查询邮件地址多行合并一行,再发送邮件
本文链接: https://lsjlt.com/news/39510.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-10-23
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0