1、不使用触发器,而是job,写个存储过程,用job调用存储过程,每小时执行一次。 2、存储过程(大概) DECLARE cursor_name CURSOR FOR select * from 表 where receiver is null and aa<dateadd(hour,12,getdate()) order by aa FOR READ ONLY open cursor_name FETCH NEXT FROM cursor_name INTO @aa, ... --看表的有用字段,需要定义变量WHILE @@FETCH_STATUS = 0 BEGIN --这里写发消息的程序
-- Get the next record. FETCH NEXT FROM cursor_name INTO @aa, ... --看表的有用字段,需要定义变量 ENDCLOSE cursor_name DEALLOCATE cursor_name
Create proc Test As If Exists(Select * from 表 where datediff(hour,aa,getdate())>=12 and IsNull(receiver,'') = '') exec master..xp_cmdshell ' net send lizheng 您有一紧急文件XXX要马上读 'go再用job执行此存储过程。
Create proc 通知您有紧急文件要读 As If Exists(Select * from 表 where datediff(hour,aa,getdate())>=12 and IsNull(receiver,'') = '') exec master..xp_cmdshell ' net send lizheng 您有一紧急文件XXX要马上读 'lizheng这个计算机名是变化的,它是根据用户登录的不同而计算机名不同,请问这如何实现啊?
1、提示就像csdn的“你有短消息”,不指明有多少,什么内容Create proc 通知您有紧急文件要读 As If Exists(Select * from 表 where datediff(hour,aa,getdate())>=12 and IsNull(receiver,'') = '') begin declare @sql varchar(1000) set @sql = 'master.dbo.xp_cmdshell '' net send ' + host_name() + ' 您有紧急文件要马上读''' exec(@sql ) End2、指明条数Create proc 通知您有紧急文件要读 As declare @sql varchar(1000) declare @cnt int Select @cnt=count(*) from 表 where datediff(hour,aa,getdate())>=12 and IsNull(receiver,'') = ''If @cnt>0 begin set @sql = 'master.dbo.xp_cmdshell '' net send ' + host_name() + ' 您有' + cast(@cnt as varchar(20)) + '个紧急文件要马上读''' exec(@sql ) End3、指明第一条内容条数Create proc 通知您有紧急文件要读 As declare @sql varchar(1000) declare @内容 varchar(200)
Select top 1 @内容=内容字段 from 表 where datediff(hour,aa,getdate())>=12 and IsNull(receiver,'') = '' order by aa If @内容 is not null begin set @sql = 'master.dbo.xp_cmdshell '' net send ' + host_name() + ' 您有一紧急文件'+@内容+'要马上读''' exec(@sql ) End
触发器只能由INSERT,UPDATE,DELETE触发
在lizheng上也要建立相应的Web程序用于相应请求。
2、存储过程(大概)
DECLARE cursor_name CURSOR
FOR select * from 表
where receiver is null
and aa<dateadd(hour,12,getdate())
order by aa
FOR READ ONLY open cursor_name
FETCH NEXT FROM cursor_name
INTO @aa, ... --看表的有用字段,需要定义变量WHILE @@FETCH_STATUS = 0
BEGIN
--这里写发消息的程序
-- Get the next record.
FETCH NEXT FROM cursor_name
INTO @aa, ... --看表的有用字段,需要定义变量
ENDCLOSE cursor_name
DEALLOCATE cursor_name
As
If Exists(Select * from 表 where datediff(hour,aa,getdate())>=12 and IsNull(receiver,'') = '')
exec master..xp_cmdshell ' net send lizheng 您有一紧急文件XXX要马上读 'go再用job执行此存储过程。
或是有谁能提供如何发送到手机上吗?有何条件?
我做了一个网络办公的软件(asp.net 加 sqlserver2000),当局域网内部的人有12个小时以上没有访问该WEB办公时,当然也就看不到是不是有人发公文过来了.这时我就是发一个条类似信使服务的消息给他(如果他机器是开着的话),如果没有开就隔一小时再发,直到他打开文件,读了文件改变了数据库内容后系统就知道条件不成立了,就不发了.
[email protected]
你有没有看懂我的意思啊?我的问题是专门针对那些电脑已经打开,可是没有在浏览器内打开http://服务器名/weboa的人.
其实最好的方法是发消息到他手机上.
或是有谁能提供如何发送到手机上吗?有何条件?
As
If Exists(Select * from 表 where datediff(hour,aa,getdate())>=12 and IsNull(receiver,'') = '')
exec master..xp_cmdshell ' net send lizheng 您有一紧急文件XXX要马上读 'lizheng这个计算机名是变化的,它是根据用户登录的不同而计算机名不同,请问这如何实现啊?
As
If Exists(Select * from 表 where datediff(hour,aa,getdate())>=12 and IsNull(receiver,'') = '')
begin
declare @a varchar(100),@sql varchar(300),@msg varchar(100)
set @a = host_name() -- 或者其它变量
set @msg = '您有一紧急文件XXX要马上读'
set @sql = '''net send ' + @a + '' + @msg + ''
exec('master.dbo.xp_cmdshell ' + @sql )
End
2:字符型日期加上引号后与日期型字段比较时系统会自动转换成日期型
也可以用cast(aa as datetime) 或 convert(datetime,aa)转换
服务端可以把网站一直打开,在程序里面判断如果当前的机器是服务器就
每隔一小时调用一次存储过程.
问题已经解决:感谢txlicenhe(马可&不做技术高手)
As
If Exists(Select * from 表 where datediff(hour,aa,getdate())>=12 and IsNull(receiver,'') = '')
begin
declare @sql varchar(1000)
set @sql = 'master.dbo.xp_cmdshell '' net send ' + host_name() + ' 您有紧急文件要马上读'''
exec(@sql )
End2、指明条数Create proc 通知您有紧急文件要读
As
declare @sql varchar(1000)
declare @cnt int
Select @cnt=count(*) from 表 where datediff(hour,aa,getdate())>=12 and IsNull(receiver,'') = ''If @cnt>0
begin
set @sql = 'master.dbo.xp_cmdshell '' net send ' + host_name() + ' 您有' + cast(@cnt as varchar(20)) + '个紧急文件要马上读'''
exec(@sql )
End3、指明第一条内容条数Create proc 通知您有紧急文件要读
As
declare @sql varchar(1000)
declare @内容 varchar(200)
Select top 1 @内容=内容字段 from 表 where datediff(hour,aa,getdate())>=12 and IsNull(receiver,'') = '' order by aa
If @内容 is not null
begin
set @sql = 'master.dbo.xp_cmdshell '' net send ' + host_name() + ' 您有一紧急文件'+@内容+'要马上读'''
exec(@sql )
End
我现在想到了不用job,完全用.net编程实现的办法:
服务端可以把网站一直打开,在程序里面判断如果当前的机器是服务器就
每隔一小时调用一次存储过程.
问题已经解决:感谢txlicenhe(马可&不做技术高手)
这样不行,因为你每次都是发给服务器了,host_name() 取出的是调用的机器
set @sql = 'master.dbo.xp_cmdshell '' net send ' + host_name() + ' 您有紧急文件要马上读'''
host_name() 的值应该是固定的吧?因为这个存储过程是在数据库服务器上的作业中执行。如果我也想不用程序解决,可是好像得不到变化的对方计算机名啊,除非在这个表中加个字段存储对方的计算机名?