当前位置: 代码迷 >> Sql Server >> 急需 存储过程~该如何处理
  详细解决方案

急需 存储过程~该如何处理

热度:342   发布时间:2016-04-27 13:55:05.0
急需 存储过程~~!
(1)为表写一个通用存储过程,传入表具编号(MeterNo)和日期(Dt),可以返回该表的24小时的数据(1—24小时,24条记录),数值(Qty)保留两位小数。


表如下:
DANo(char(32),not null)
MeterNo(char(20),not null)
MeterType(char(4),not null)
DATime(datetime,not null)
LogTime(datetime,not null)
DAType(char(3),null)
Qty(decimal(18,6),not null)
Qty01(decimal(18,6),not null)
Qty02(decimal(18,6),null)
Note(nvarchar(50),null)


(2)Alter PROCEDURE Usp_SpecialMonitorGetDX (
@MeterNo Char(32)
)
as 
Begin
Declare @DATime Datetime;
  Begin 
  set @DATime=(select max(DATime) from SpecialMonitorData where [email protected])
   
  select Qty from SpecialMonitorData where [email protected] and [email protected]
  end
end
Create PROCEDURE Usp_SpecialMonitorGetDX (
@MeterNo Char(32)
)
as 
Begin
Declare @DATime Datetime;
  Begin 
  set @DATime=(select max(DATime) from SpecialMonitorData where [email protected])
   
  select Qty from SpecialMonitorData where [email protected] and [email protected]
  end
end


以这个存储过程为基础, 增加条件判断超过1小时无数据,则发送报警,数据比上一次过大,则发送报警,取最接近当前时间的值

------解决方案--------------------
SQL code
create proc up_t    @tb varchar(1000)asbegin    declare @sql nvarchar(max)='';    declare @d varchar(20)=convert(varchar(10),getdate(),120);    set @sql=' select * from [[email protected]+'] where [datetime] between [email protected]+''' and [email protected]+' 23:59:59.997''';    exec(@sql);end-- 在上层用dataset取数据吧。-- 不清楚你那个值是什么意思
  相关解决方案