Unanswered: A function to return number of records
I am trying to write a function that returns the number of records present in a table. But in this case i want to pass 'TABLENAME' as a parameter to this function and then retrieve numrecords henceforth.
This is how I'm currently trying to retrieve it -->
FUNCTION GetNumRecords(@tablename as nvarchar(20))
return int as
Declare @numrecs as int
Set @numrecs = (Select Count(*) from @tablename)
I'm getting the following error:
Must declare the variable '@tablename'.
But i am already passing @tablename as a parameter to the function and I dont exactly understand where the problem is!! Why can't I use a local variable in a SELECT statement like this.