|
Posted by Erland Sommarskog on 08/20/07 14:48
aCe (acerahmat@gmail.com) writes:
> i want to make a FN that can check record exist or not.
> this is my FN:
> CREATE FUNCTION ufnCheckExists(
>...
> error msg :
> Msg 1087, Level 15, State 2, Procedure ufnCheckExists, Line 25
> Must declare the table variable "@table".
>
> is it possible to create it. or any suggestion.
> my purpose to create this, is i can reuse my function without creating
> ambiguous function.
Simply forget it. This is T-SQL, this is not C#. While code reuse is a
virtue in T-SQL, it is not as big virtue as in an traditional programming
langauge. Specifically, it's very rarely a good idea to parameterise on
the table name.
For a longer discussion on dynamic SQL, see this article on my web
site: http://www.sommarskog.se/dynamic_sql.html.
--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
[Back to original message]
|