您好,登錄后才能下訂單哦!
--創建測試表
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'
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。