Is it the same as executing a stored procedure?
1 Answer
No, a SQL function must be referenced with its schema name and must be part of the appropriate part of a SELECT statement. For scalar-valued functions this is something like SELECT dbo.MyLookupFunction(12). For a table-valued function, SELECT columnA, columnB, columnC FROM dbo.MyTableLookupFunction(12). See CREATE FUNCTION (Transact-SQL) and Executing User-Defined Functions (Database Engine) for more information about functions in SQL.
The java code is, of course, the same as for any other query.
4 Comments
mre
When I try
SELECT dbo.MyLookupFunction(12), i get the following exception, com.microsoft.sqlserver.jdbc.SQLServerException: The value is not set for the parameter number 1.JamieSee
12 is just an example, if you're using parameters with your java code try replacing the 12 with ? and execute that. Java's classes for this expect place holders to match the parameters. Parameters in SQL can be expressed in 2 ways, unnamed by using a ?, and named using @parametername.
mre
I'm using the
? character, but it's still not working. Is SELECT dbo.MyLookupFunction(?,?) valid?JamieSee
Add the code you're using to your question. That should be valid.