Sql query email address multiple lines merge one line, and then send mail
-- create a test table use FlygoIF OBJECT_ID ('test') IS NOT NULL DROP TABLE testCREATE TABLE test (Id int IDENTITY (1p1) NOT NULL, Name varchar (50) NULL, Judge char (1) NULL, Mail varchar (50) NULL) GO-- to insert test data INSERT INTO test (Name, Judge, Mail) SELECT' Zhang San', 'Yaojingjue qq.com' UNION ALL SELECT'Li Si','Y' The GOSELECT * FROM test-- query merges DECLARE @ Maliaddress varchar (8000) set @ Maliaddress ='+ STUFF ((SELECT') '+ Mail FROM test WHERE Judge in (' Y') FOR xml path (''), 1) select @ Maliaddress as' MailAddress' exec msdb.dbo.sp_send_dbmail@profile_name = 'Fly_Huang', @ recipients = @ Maliaddress, @ subject =' subject of Test email', @ body = 'body of Test email' @ body_format = 'HTML'