有沒有一種方法可以讓我在下面的查詢中添加時間,我的電子郵件正文:添加具有sp_send_dbmail電子郵件(數據庫郵件)的體內動態內容
EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'TEST_DEV',
@recipients = '[email protected]',
@query = ' select
Percentage = CONVERT(DECIMAL(10,1),100 - (CAST(COUNT(DISTINCT case when PD.Exception != ' ' then PD.Id END) as float)/CAST(COUNT(PD.Id) as float)*100))
from
DataBaseName.dbo.Product P INNER JOIN DataBaseName.dbo.LogProduct PD
ON P.LogId = PD.LogId
WHERE
ResponseTime < GETDATE() and RequestTime > DATEADD(MINUTE, -150, GETDATE())
' ,
@subject = 'Test',
@body = 'Please check the attached file for Providers with Many unsuccessful calls between the time xx an yy',
@attach_query_result_as_file = 1 ;
在當前行
@body = 'Please check the attached file for info on calls between the time xx an yy',
我想添加GetDate()來代替xy和DATEADD(MINUTE,-150,GETDATE())來代替yy嗎?
是否有可能?
declare @body nvarchar(max)
EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'DEV',
@recipients = '[email protected]',
@query = 'exec Database.dbo.spTest' ,
@subject = 'Test',
select @body = 'Please check the attached file for info on calls between the time ........................',
@attach_query_result_as_file = 1 ;
你想讓我做這樣的事嗎?
'@ body'參數的類型應該是'NVARCHAR(something)'。 [鏈接](http://technet.microsoft.com/en-us/library/ms190307.aspx) –
謝謝,更正。我正在看同一頁,並沒有看到'varchar'之前的'n' O.o –
嘿tommy_0,我更新了我的答案?這是你的意思嗎 ?它不起作用,但我不確定我是否正確理解了你的觀點。你是指將@body變量傳遞給sp_send_dbmail。你能看看我編輯的答案並讓我知道嗎? – CodeNinja