日期:2014-05-17 浏览次数:20798 次
DECLARE @html NVARCHAR(MAX)
set @html='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body><table cellspacing="0" cellpadding="0" bordercolor="#CCCCCC" border="0" frame="hsides" rules="all" >'
SET @html = @html + CAST((
--未准时回签
select MA002+' ' td,MV002+' ' td,TC003 + ' ' td,TD001+'-'+TD002+'-'+TD003 + ' ' td,TD004 + ' ' td,TD005+' ' td,convert(int,TD008) td,' '+TD010 td
from COPTD JOIN COPTC ON TC001=TD001 AND TC002=TD002 JOIN COPMA ON MA001=TC004 LEFT JOIN CMSMV ON MV001=TC006
LEFT JOIN INVMB ON MB001=TD004
left join
(
select CTD001,CTD002,CTD003,C_ID,CTD006
FROM COPTD_delivery D1
where CTD006
IN (SELECT MAX(CTD006) FROM COPTD_delivery D2 where D2.CTD001=D1.CTD001 AND
D2.CTD002=D1.CTD002 AND D2.CTD003=D1.CTD003 )
) xxx on CTD001=TD001 AND CTD002=TD002 AND CTD003=TD003
WHERE DATEDIFF(DAY,TC003,convert(char(8),getdate(),112)) >=2 AND MB025 NOT IN ('C','P') AND CTD006 IS NULL AND TC003 >='20130701' and TD016='N' AND TD021='Y' and TD001 not IN ('2204','2205','2209')
order by TC003,MA002
for xml path ('tr')
) AS VARCHAR(MAX)) + '</table></body></html>'
EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'ERP_mail',
@recipients='', --邮件地址,多个;分开。
@subject = @message1,
@body = @html,
@body_format = 'HTMl' ;
end