Terry,
You get an error because it's not allowed in SQL Server. In a sproc you can build dynamic SQL and run it using EXECUTE command or sp_executesql system sproc. I'm not sure what you can do in UDF.
>The following UDF works fine w/o the @tablename param, but with a static tablename instead.
>
>ALTER FUNCTION dbo.GetDesc (@tablename varchar(100), @id int)
>RETURNS varchar(400) AS
>BEGIN
>return (select name from @tablename where id = @id)
>END
>
>With the @tablename param, I get error:
>@tablename must be declared
>
>Does anyone see the problem here?
>TIA
--sb--