Applies to: MS SQL 2008 and Sybase, the ODBC driver, as reported in 2010; the thread names no Clarion version.
Problem
On Sybase, &ReturnValue = CALL [af].[fn_ElementStart(1) returned the function value. The same on MS SQL gave "The request for procedure 'fn_ElementStart' failed because 'fn_ElementStart' is a function object". The poster wanted to keep the functions, which are also used inside SELECT statements.
Solution
- Do not use CALL for a scalar function on MS SQL. One poster explained that the driver then creates a cursor and uses output parameters, which functions do not support. Without CALL the
&text reaches the server as it is. - Select the function through PROP:SQL, with a dummy table whose first field receives the value:
DummyTable{Prop:Sql} = 'select dbo.MyFunction()', then NEXT and read the field. Two posters used this; the dummy file had CSTRING fields. - This returned an empty value, with no error, for the original poster until he cast the result:
SELECT CAST([AF].[fn_ElementStart](1) AS varchar) AS ReturnValue. With the CAST the file driver knew how to handle the value. He also found the FROM clause and the dummy table were not needed (he had a TOP 1 as well).
Caveats
- Rick M. had not tested a function that returns binary data into a BLOB.
- One poster advised that scalar functions inside a SELECT are not optimised and can be slow on large result sets; table-valued functions work better, sub-queries or CASE better still.
Today (2026)
Not re-tested. The CAST is what made the value arrive for the poster; likely still needed for types the driver cannot map.
Sources: Gordon H. (Mar 2010, the question and the answer), Dennis E., Sergio M., Rick M. (Mar 2010) in softvelocity.clarion.databasedrivers.