I have got two SQLServer2008 user-defined functions: fn_Top and fn_Nested. The first one, fn_Top, is structured in this way:
CREATE FUNCTION [dbo].[fn_Top]
RETURNS @Results table (
MyField1 nvarchar(2000),
MyField2 nvarchar(2000)
)
AS
BEGIN
INSERT INTO
@Results
(
MyField1,
MyField2
)
SELECT
item,
(SELECT MyString FROM dbo.fn_Nested(x.MyCounter))
FROM
OtherTable x
RETURN
END
I would like to perform a sort of dynamic parameter passing to the second function, fn_Nested, reading the values of the numeric field MyCounter in the table OtherTable.
Fact is, x.MyCounter is not recognized as a valid value. Everething works fine, on the other hand, if I set in fn_Nested a static parameter, IE dbo.fn_Nested(17).
Is there anyone who can suggest a workaround to solve this problem ? Thanks in advance.