- /*声明变量*/
- declare @tableHTML varchar(max)
- declare @mail nvarchar(200);
- declare @note nvarchar(500);
- --设置问候词
- set @tableHTML = '<html><body><table><tr><td><p><font color="#000080" size="3" face="Verdana">您好!</font></p><p style="margin-left:30px;"><font size="3" face="Verdana">请审批下面的价格申请:</font></p></td></tr>';
- --设置表头
- set @tableHTML=@tableHTML
- +'<tr><td><table border="1" style="border:1px solid #d5d5d5;border-collapse:collapse;border-spacing:0;margin-left:30px;margin-top:20px;"><tr style="height:25px;background-color: rgb(219, 240, 251);">
- <th style="width:100px;">RFQ No</th>
- <th style="width:200px;">sales</th>
- <th style="width:60px;">PL3</th>
- <th style="width:80px;">Customer</th>
- <th style="width:100px;">disty_name</th>
- <th style="width:60px;">2nd disty</th>
- <th style="width:80px;">Sold To Customer</th>
- <th style="width:80px;">Part No</th>
- <th style="width:100px;">Currency</th>
- <th style="width:60px;">Volume</th>
- <th style="width:100px;">Requested DC</th>
- <th style="width:100px;">Customer RP</th>
- <th style="width:100px;">Competitor</th>
- <th style="width:100px;">Competitor PN</th>
- <th style="width:80px;">Competitor Price</th></tr>';
- --启用游标
- declare c cursor for
-
- --查询结果
-
- select
- a.email
- ,a.note
- ,@tableHTML+'<tr><td align="center">'+rfq_quotation_number+'</td>'
- +'<td align="center">'+lastname+'</td>'
- +'<td align="center">'+pl3+'</td>'
- +'<td align="center">'+customer+'</td>'
- +'<td align="center">'+disty_name+'</td>'
- +'<td align="center">'+snd_disty+'</td>'
- +'<td align="center">'+sold_to_customer+'</td>'
- +'<td align="center">'+fully_part_no+'</td>'
- +'<td align="center">'+currency+'</td>'
- +'<td align="center">'+volume+'</td>'
- +'<td align="center">'+requested_disty_cost+'</td>'
- +'<td align="center">'+cust_requested_price+'</td>'
- +'<td align="center">'+competitor+'</td>'
- +'<td align="center">'+competitor_part_no+'</td>'
- +'<td align="center">'+Competitor_Price+'</td></tr>'
- from
- (
- select
- email
- ,note
- ,rfq_quotation_number
- ,lastname
- ,pl3
- ,客户中文+'/'+客户英文 as customer
- ,disty_name
- ,snd_disty
- ,sold_to_customer
- ,fully_part_no
- ,currency
- ,isnull(cast(volume as nvarchar(10)),'') volume
- ,isnull(cast(requested_disty_cost as varchar(10)),'') requested_disty_cost
- ,isnull(cast(cust_requested_price as varchar(10)),'') as cust_requested_price
- ,isnull(cast(competitor as varchar(100)),'') competitor
- ,isnull(cast(competitor_part_no as varchar(50)),'') competitor_part_no
- ,isnull(cast(competitor_price as varchar(10)),'') competitor_price
- from cux_rfq_v
- where currentnodetype = 1 and lastoperatedate + ' '+ lastoperatetime >= DATEADD(MINUTE,-60,GETDATE()) --找最近60分的记录,并发送
- ) a
- open c
- fetch next from c into
- @mail
- ,@note
- ,@tableHTML;
- while @@FETCH_STATUS = 0
-
- begin
-
- EXEC msdb.dbo.sp_send_dbmail
- @profile_name= '<账户名>', --定义好的sql server 邮箱账户名
- ,@recipients=@mail
- ,@subject=@note
- ,@body= @tableHTML
- ,@body_format='HTML'
- fetch next from c into
- @mail
- ,@note
- ,@tableHTML;
- end
- close c;
- deallocate c;