declare @Hd decimal(18,1)
set @Hd=12
select zh_k,Lp,S,L20,Lr,C0,43.5/Lr as SSI
from(
select L20*Te*case season
  when '春融' then (select spring from design_ssi where road_name='连霍路')
  when '干季' then (select dry from design_ssi where road_name='连霍路')
  when '雨季' then (select ran from design_ssi where road_name='连霍路')
  when '冻前' then (select freeze from design_ssi where road_name='连霍路')
end as 'Lr',*
from(
select zh_k,case when @Hd=20 then 1 else 1*C0+2 end as Te,(av+1.645*S) as L20,season,dat,av as Lp,S,C0
from
(select zh_k,avg(av) as av,stdev(av) as S,season,C0,dat from ssi
where lufu='左' and road_name='连霍路' and year(dat)='2004' and month(dat)='1'
group by zh_k,season,dat,C0)a
)b)c这段话的查询结果如下:
zh_k    Lp    S    L20    Lr    C0    SSI
12 2.218200 1.0757619160390461 3.9878283518842306 88.290519710716865 16.0 0.49269162920919912
999 3.075000 0.69348471694160529 4.2157823593689407 93.337421436428357 16.0 0.4660510150221755

解决方案 »

  1.   

    好象,连起来了,更正:
    zh_k    Lp    S    L20    Lr    C0    SSI
    12  2.218200  1.0757619160390461  3.9878283518842306  88.290519710716865  16.0 0.49269162920919912
    999  3.075000  0.69348471694160529  4.2157823593689407  93.337421436428357  16.0  0.4660510150221755
      

  2.   

    hehe,低级错误哦,竟然没人发现,兄弟,分给你了呵呵
      

  3.   

    更正为:
    create table #t_ssi
    (zh_k int,Lp decimal(18,3),S decimal(18,3),L20 decimal(18,3),
    C0 decimal(18,3),Lr decimal(18,3),SSI decimal(18,3),Score char(2))