通过触发器在SQL中发送SMS [英] Send SMS in SQL through trigger

查看:72
本文介绍了通过触发器在SQL中发送SMS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的,



我已经创建了一个通过SQL发送短信的触发器,但是如何在SQL中放置httpget请帮我解决这个问题。

以下是触发器。请注意,java脚本代码工作正常。



Dear,

I have created a trigger for sending sms through SQL, But how to put httpget in SQL please help me on this.
Below is the trigger. Note that java script code working fine.

alter TRIGGER CallInserted
ON [dbo].[CustomerCall]
FOR INSERT
AS
BEGIN
    SET NOCOUNT ON;
 
    IF EXISTS (SELECT * FROM inserted)
    BEGIN
	//below is javascript code working fine, But i want to use in SQL
	function httpGet(theUrl)
	{
    	var xmlHttp = new XMLHttpRequest();
    	xmlHttp.open( "GET", theUrl, false ); // false for synchronous request
    	xmlHttp.send( null );
    	return xmlHttp.responseText;
	}
	
    END
END
GO



谢谢

Basit。


Thanks
Basit.

推荐答案

javascript代码在sql中不起作用



您可以通过Sql发送电子邮件,例如



步骤1)创建配置文件和帐户



您需要使用配置数据库邮件向导创建配置文件和帐户,可以从配置中访问管理节点中数据库邮件节点的数据库邮件上下文菜单。此向导用于管理帐户,配置文件和数据库邮件全局设置



步骤2)



运行:



sp_CONFIGURE'show advanced',1

GO

RECONFIGURE

GO

sp_CONFIGURE'Database Mail XPs',1

GO

RECONFIGURE

GO

步骤3)



USE msdb

GO

EXEC sp_send_dbmail @ profile_name ='yourprofilename',

@ recipients ='test @ Example.com',

@ subject ='测试消息',

@ body ='这是测试消息的正文。

祝你成功收到数据库邮件。'

循环播放表格



DECLARE @email_id NVARCHAR(450),@ id BIGINT,@ max_id BIGINT,@ query NVARCHAR(1000)



SELECT @ id = MIN(id),@ max_id = MAX(id)FROM [email_adresses]



WHILE @ id< @max_id

BEGIN

SEL ECT @ email_id = email_id

FROM [email_adresses]



set @ query ='sp_send_dbmail @profile_name =''yourprofilename'',

@recipients ='''+ @ email_id +''',

@subject =''测试信息'',

@ body =''这是测试消息的正文。

祝贺你成功收到数据库邮件。'''



EXEC @query

SELECT @ id = MIN(id)FROM [email_adresses]其中id> @id



END
The javascript code does not work in sql

You can send email via Sql like

Step 1) Create Profile and Account

You need to create a profile and account using the Configure Database Mail Wizard which can be accessed from the Configure Database Mail context menu of the Database Mail node in Management Node. This wizard is used to manage accounts, profiles, and Database Mail global settings

Step 2)

RUN:

sp_CONFIGURE 'show advanced', 1
GO
RECONFIGURE
GO
sp_CONFIGURE 'Database Mail XPs', 1
GO
RECONFIGURE
GO
Step 3)

USE msdb
GO
EXEC sp_send_dbmail @profile_name='yourprofilename',
@recipients='test@Example.com',
@subject='Test message',
@body='This is the body of the test message.
Congrates Database Mail Received By you Successfully.'
To loop through the table

DECLARE @email_id NVARCHAR(450),@id BIGINT,@max_id BIGINT,@query NVARCHAR(1000)

SELECT @id=MIN(id),@max_id=MAX(id) FROM [email_adresses]

WHILE @id<@max_id
BEGIN
SELECT @email_id=email_id
FROM [email_adresses]

set @query='sp_send_dbmail @profile_name=''yourprofilename'',
@recipients='''+@email_id+''',
@subject=''Test message'',
@body=''This is the body of the test message.
Congrates Database Mail Received By you Successfully.'''

EXEC @query
SELECT @id=MIN(id)FROM [email_adresses] where id>@id

END


这篇关于通过触发器在SQL中发送SMS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆