Posted by SQL Server on 04/19/07 21:42
I am writing a function which will take two parameters. One the field
to be returned from a table and second parameter is the ID of the
record to be returned.
Problem is it's not returning the value of the field specified in the
parameter but instead returns the parameter itself. Is there a
function that will get the parameter to be evaluted first?
ALTER FUNCTION [dbo].[getScholarYearData]
(
-- Add the parameters for the function here
@FieldName varchar(50), @ScholarID int
)
RETURNS varchar(255)
AS
BEGIN
-- Declare the return variable here
DECLARE @ResultVar varchar(255)
-- Add the T-SQL statements to compute the return value here
SELECT @ResultVar=EXECUTE(@FieldName)
FROM dbo.qmaxScholarYearID INNER JOIN
dbo.tblScholarYears ON
dbo.qmaxScholarYearID.ScholarID = dbo.tblScholarYears.ScholarID AND
dbo.qmaxScholarYearID.MaxOfScholarYearID =
dbo.tblScholarYears.ScholarYearID
-- Return the result of the function
RETURN @ResultVar
END
Navigation:
[Reply to this message]
|