高分求存储过程语句,难~

sunshineos 2006-04-28 09:54:11
AS
begin
--定义当前整点时间变量
declare @nowtime as varchar(20)
select @nowtime =( dateadd(hh,convert(int,convert(varchar(2),getdate(),8)),convert(datetime,convert(varchar,getdate(),112))))

--清空weatemp表
TRUNCATE TABLE weatemp
--开始插入每个表当前整点数据数据

insert into weatemp
select stationname as 自动站名称 ,
OutsideTemp as 气温 ,
barameter as 气压 ,
mainWinddir as 风向 ,
windspeed as 风速 ,
Rain as 雨量 ,
OutsideHum as 湿度
from ze007record
where rstime =@nowtime


..............

insert into weatemp
select stationname as 自动站名称 ,
OutsideTemp as 气温 ,
barameter as 气压 ,
mainWinddir as 风向 ,
windspeed as 风速 ,
Rain as 雨量 ,
OutsideHum as 湿度
from ze021record
where rstime =@nowtime




现在遇到个问题,就是当某个自动站坏了之后,也就是表中查不到
rstime 等于当前时间的记录,如何向weatemp 表中 插入
自动站名称 =***自动站 ,气温,气压等其他值为"/"呢

ze007record 自动站的表 stationname是varchar类型,都为预设值(如***自动站),其他列都为float 和int类型
weatemp 表中的数据类型我都是varchar

这个存储过程 语句怎么写呢? 救命啊~

...全文
161 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
子陌兄正解。
十一月猪 2006-04-28
  • 打赏
  • 举报
回复

if exists(select 1 from ze021record where rstime=@nowtime)
begin
insert into weatemp
select stationname as 自动站名称 ,
OutsideTemp as 气温 ,
barameter as 气压 ,
mainWinddir as 风向 ,
windspeed as 风速 ,
( case Rain when -32768 then '缺测' else Rain )as 雨量 ,
OutsideHum as 湿度
from
ze021record
where
rstime =@nowtime
end
else
begin
insert into weatemp select '***自动站','/','/','/','/','/','/'
end
sunshineos 2006-04-28
  • 打赏
  • 举报
回复
谢谢 ibin_ftsafe(子陌红尘) 结分了
bg54 2006-04-28
  • 打赏
  • 举报
回复
你就做一个作业把
子陌红尘 2006-04-28
  • 打赏
  • 举报
回复
insert into weatemp
select stationname as 自动站名称 ,
case OutsideTemp when -32768 then '缺测' else rtrim(OutsideTemp) end as 气温,
case barameter when -32768 then '缺测' else rtrim(barameter) end as 气压,
case mainWinddir when -32768 then '缺测' else rtrim(mainWinddir) end as 风向,
case windspeed when -32768 then '缺测' else rtrim(windspeed) end as 风速,
case Rain when -32768 then '缺测' else rtrim(Rain) end as 雨量,
case OutsideHum when -32768 then '缺测' else rtrim(OutsideHum) end as 湿度
from
ze021record
where
rstime =@nowtime
sunshineos 2006-04-28
  • 打赏
  • 举报
回复
每个小时清空weatemp表
再读数据 插入 weatemp表中啊
wxmaizi 2006-04-28
  • 打赏
  • 举报
回复
你是要做Update还是Insert啊
sunshineos 2006-04-28
  • 打赏
  • 举报
回复
唉 原来语句这个简单 就是想不到
那再请问高手
如果 某个自动站表中 比如Rain列中 它的值为-32768
我怎么 在weatemp表中Rain列中插入的是 '缺测'呢
有好多表 每个表中 有6个数据列

怎么写比较好?
子陌红尘 2006-04-28
  • 打赏
  • 举报
回复
if exists(select 1 from ze021record where rstime=@nowtime)
begin
insert into weatemp
select stationname as 自动站名称 ,
OutsideTemp as 气温 ,
barameter as 气压 ,
mainWinddir as 风向 ,
windspeed as 风速 ,
Rain as 雨量 ,
OutsideHum as 湿度
from
ze021record
where
rstime =@nowtime
end
else
begin
insert into weatemp select '***自动站','/','/','/','/','/','/'
end
sunshineos 2006-04-28
  • 打赏
  • 举报
回复
沙发自己做了,顶上去

34,576

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧