if(exists(select  1 from 表1 where 列1=b.列1)
begin
select 列1,a.列2,列3=b.列2*a.列5  
from 表2 b,表1 a 
where a.列1=b.列1
union all
select 列1,a.列2,列3=b.列3*a.列6  
from 表2 b,表1 a 
where a.列1=b.列1
...
end

解决方案 »

  1.   

    select A.列1,A.列2,B.列2*A.列5*A.列6*A.列7...*A.列20 as 列3 from 表A A,表B B where A.列1 = B.列1
      

  2.   

    有 A B C 3个表 :
    表A:
    列1   列2  列3  列4   列5  列6   列7  .......
    A     1    2    3     4    5     6   .......表B
    列1   列2  列3  列4   列5  列6   列7表C
    列1   列2  列3  当表B输入数据,并表A列1的数据等于表B列1的数据时,即 : 
    列1   列2  列3  列4   列5  列6   列7
    A     8    9     10   11   12   13
    表B中的列2数据乘以表A的列5到列20的数,(表A中的 列6以后数据不一定有,可能为空。)
    把运算的结果写入表C:
    结果如下:
    列1   列2  列3  
    A     1     32
    A     1     40
    A     1     48
    A     1     56
    ..    ..     ..
      

  3.   

    表C中的列2中的数据为表A列2的数据,表A中的列6以后的数据没有的话就为空,表C的列3只插入表A列5后存在的数据与表B列2相乘所得出的结果。
      

  4.   

    create trigger tri_B
    on B
    for insert
    as
    begin    insert C
        select * 
        from ( select a.列1,a.列2,b.列2*a.列5
               from a join inserted b on a.列1=b.列1
               where a.列5 is not null
               union all
               select a.列1,a.列2,b.列2*a.列6
               from a join inserted b on a.列1=b.列1
               where a.列6 is not null
               union all
               ......
               union all
               select a.列1,a.列2,b.列2*a.列20
               from a join inserted b on a.列1=b.列1
               where a.列20 is not null
             ) dend
    go