I've got a table that holds a rate value and an effective date:
I'm trying to make a Function that will return the value of AdminCost column for a single record, I'm able to get that record with this query just fine:Code:ID | EffectiveDate | AdminCost 1 | 2000-01-01 | 200.00 2 | 2010-01-01 | 225.00 3 | 2012-01-01 | 250.00Which means when the date passed in is between "Jan 1 2010" and "Jan 1 2012" it returns the '225.00' and I'm trying to set that value to a function variable to return it to the Stored Proc that calls this, but when I try set it to a variable, I get an error, here's the function I'm trying to create:Code:Select Top 1 AdminCost, max(ID) from tbl_pwe_tcr_DefaultAmounts where EffectiveDate < @EntryDate Group By ID, AdminCostThe error I'm getting is:Code:Create Function [dbo].[fn_GetAdminFee] (@EntryDate DateTime) Returns numeric(6, 2) As Begin Declare @Amount numeric(6, 2) Select Top 1 @Amount = AdminCost, max(ID) from tbl_pwe_tcr_DefaultAmounts where EffectiveDate < @EntryDate Group By ID, AdminCost Return @Amount EndSo my question is, how can I assign the the AdminCost column to the @Amount variable?Code:A SELECT statement that assigns a value to a variable must not be combined with data-retrieval operations.
I've also tried:but that doesn't work either.Code:Declare @Amount numeric(6, 2) Select @Amount = AdminCost From (Select AdminCost, max(ID) from tbl_pwe_tcr_DefaultAmounts where EffectiveDate < @EntryDate Group By ID, AdminCost)




Reply With Quote