Multiply by largest row and append to list

Viewed 52

I have the following in two tables:

(SFR_MAIN)

SQ. FT. AREA     1         2
400          86.6600    86.7300
500          82.3300    82.4000
600          78.9600    79.0200
700          76.2100    76.2700
800          73.9100    73.9700
900          71.9400    71.9900
1000         70.2200    70.2700
1100         68.7000    68.7500
1200         67.3400    67.3900
1300         66.1200    66.1600
1400         65.0000    65.0400
1600         63.0400    63.0800
1800         61.3600    61.3900
2000         59.8900    59.9300
2200         58.6000    58.6300
2400         57.4400    57.4700
2600         56.3900    56.4200
2800         55.4400    55.4700
3000         54.5700    54.6000

And

(MULT)

SQ. FT. AREA    MULTIPLIER
3100            0.992
3200            0.986
3300            0.978
3400            0.971
3500            0.964
3600            0.958
3700            0.952
3800            0.946
4000            0.934

The idea would be to create a table with both. The problem is that the second is a multiplier that should be multiplied to that last(Largest) squarfootage in the first.

So 3100 would be .992 * 54.57 for column 1 and .992 * 54.6 for column 2, yes those are the actual names of the columns.

So the desired output would be:

SQ. FT. AREA    1          2
400          86.6600    86.7300
500          82.3300    82.4000
600          78.9600    79.0200
700          76.2100    76.2700
800          73.9100    73.9700
900          71.9400    71.9900
1000         70.2200    70.2700
1100         68.7000    68.7500
1200         67.3400    67.3900
1300         66.1200    66.1600
1400         65.0000    65.0400
1600         63.0400    63.0800
1800         61.3600    61.3900
2000         59.8900    59.9300
2200         58.6000    58.6300
2400         57.4400    57.4700
2600         56.3900    56.4200
2800         55.4400    55.4700
3000         54.5700    54.6000
3100         54.1334    54.1632
3200         53.8060    53.8356
3300         53.3695    53.3988
3400         52.9875    53.0166
3500         52.6055    52.6344
3600         52.2781    52.3068
3700         51.9506    51.9792
3800         51.6232    51.6516
4000         50.9684    50.9964

I can do one column like this:

select 
[SQ. FT. AREA],
[1]
from test.dbo.SFR_MAIN

union all

Select
[SQ. FT. AREA],
MULTIPLIER * (select
m.[1]
from test.dbo.SFR_MAIN m
inner join
    (
    select max([SQ. FT. AREA]) as mmm 
    from test.dbo.SFR_MAIN  
    ) tt on  tt.mmm = m.[SQ. FT. AREA]
 ) as [1]
from test.dbo.mult

And if I only had the two columns I would just do it twice, but I have 16 columns. Is there a way to iterate through the columns to get them all side by side in a table?

I am using SQL Server 2012

2 Answers
Related