0
我創建了一個查詢,以我需要將其呈現給客戶的方式提取信息和電子郵件。我怎樣才能把它變成由查詢(查詢A)提供的存儲過程?我需要它運行每個唯一的一組cmp_code和cmp_e_mail它返回。因此,例如,如果QueryA返回以下內容,我需要電子郵件查詢分別運行它們中的每一個。存儲過程通過電子郵件向多個收件人發送電子郵件
C0001 [email protected]
C0002 [email protected]
C0003 [email protected]
QueryA:
SELECT DISTINCT
[cmp_code]
,[cmp_e_mail]
FROM Table1
查詢電子郵件:
DECLARE @email nvarchar(50)
DECLARE @cmp_code nvarchar (5)
DECLARE @profile nvarchar(50)
DECLARE @subject nvarchar(100)
DECLARE @querystr nvarchar (MAX)
set @email = QueryA.[cmp_e_mail]
set @cmp_code = QueryA.[cmp_code]
set @profile = 'Reports'
set @subject = 'Test'[email protected]_code
set @querystr = 'SELECT [Year],[Week],[DueDate]
FROM Table1
WHERE [cmp_code] = '''[email protected]_code+'''';
EXEC msdb.dbo.sp_send_dbmail
@profile_name = @profile,
@recipients = @email,
@subject = @subject,
@body = 'This message is to inform you that we have not received your financial report for the following weeks.
Please remit as soon as possible and pay by the due date listed.',
@query = @querystr
創建2個存儲過程的優勢是什麼? – d90 2015-04-02 18:37:27
我不認爲有一個好處可能只是一個習慣,我必須保持整潔 – 2015-04-04 17:41:04