SqlServer触发器A表中插入一行数据后动态在B表中插入A表中计算后数据(二)

2014-11-24 12:08:34 · 作者: · 浏览: 2
minval out ,@maxval output
--滤掉空值
if @minval is null or @maxval is null
set @val=-1
else
begin
if @minval !=-1 and @maxval !=-1
set @val=@maxval-@minval
else
set @val=-1
end
select @val
declare @counts int
select @counts=count(*) from t_DTLJ where data_time=@time
if @counts>0
begin
--如果存在已有记录则更新记录,否则插入新纪录
select @sql='update t_DTLJ set '+@str+'=@val where data_time=@time'
set @param='@val float,@time datetime'
exec sp_executesql @sql,@param,@val,@time
end www.2cto.com
else
begin
select @sql='insert into t_DTLJ(data_time,'+@str+') values(@time,@val)'
set @param='@val float,@time datetime'
exec sp_executesql @sql,@param,@val,@time
end
end
FETCH NEXT FROM name_cursor into @station_name,@point_name
END
--关闭游标
close name_cursor
--删除游标
DEALLOCATE name_cursor