使用 select 语句在 table 中插入时更新值

Update value while inserting in a table using select statement

我正在使用 select 语句在临时 table 中插入值,每个语句调用一个 TVF,即

Insert into #Temp(Rownumber, Percentage) select * from dbo.MatchFirstName(@FirstName) 
Insert into #Temp(Rownumber, Percentage) select * from dbo.MatchLastName(@LastName)

FunctionWeights Table 中,我有 weights 列和 FunctionName 列存储不同的函数名称。

dbo.MatchFirstName(@FirstName)dbo.MatchLastName(@lasname) 是这里的 TVF。现在,我有一个名为 FunctionWeights 的 table,它存储与这些函数名称对应的常量值。现在,在将值插入 Percentage 列的 Temp table 之前,我希望它检索与 select 语句具有的函数名称对应的常量值并将其相乘从函数中检索到的百分比值。我该怎么做?

您可以加​​入 table:

insert  into #Temp
        (Rownumber, Percentage) 
select  mfn.Rownumber
,       mfn.ConstantValue * fw.Percentage
from    dbo.MatchFirstName(@FirstName) mfn
join    FunctionWeights fw 
on      mfn.FunctionName = fw.FunctionName