I have a table called FunctionWeights
which contains data as follows:
My query is as follows:
select @constVal = FunctionWeight from dbo.FunctionWeights where FunctionWeights.FunctionName = 'MatchCity'
Insert into #Temp2 select RowNumber,PercentMatch,@constVal, PercentMatch * @constVal from dbo.MatchCity(@City)
select * from #Temp2
select @constVal = FunctionWeight from dbo.FunctionWeights where FunctionWeights.FunctionName = 'MatchSSN'
Insert into #Temp2 select RowNumber,PercentMatch, @constVal, PercentMatch * @constVal from dbo.MatchSSN(@SSN)
select * from #Temp2
and so on……………. for all function names.
Data-types for columns of #Temp2 are as follows:
Rownumber int not null,
ValFromFunc float(3)null,
FuncWeight float(3) null,
Percentage float(3) not null
However, The #Temp2 table after every insert has only 1 in FunctionWeight column for all the functionNames matched as shown above in queries.
The snapshot of #Temp2
is as follows after insert for any function Name i.e FunctionWeight does not change as it should.
Best Answer
If the
FuncWeight
field in the#Temp2
table is truly defined asfloat(3)
, then the most likely problem is that the datatype of@constVal
isDECIMAL(x, 0)
or justDECIMAL
. Either of those would round up the0.7
values to be just1
, though the0.3
and0.35
values would round down to0
.Nothing in that posted code or data indicates what could force all values of
FunctionWeight
to come out as1
. Since some of theFunctionWeight
values are1
, I have to assume that the "snapshot of #Temp2" image was taken after testingFunctionName
values that have non-1
values forFunctionWeight
.Another possibility is that we are not being shown all rows in the
FunctionWeights
table and that there is duplication of theFunctionName
values where the duplicated rows have a value of1
forFuncWeight
. In that case the last record read by theselect @constVal = FunctionWeight from dbo.FunctionWeights
query would be the value stored in@constVal
, though that would not always be the "duplicated" row since there is no ORDER BY on the query.