MSSQL: capturing a stored procedure's return value in Clarion - end the procedure with a SELECT and call it with PROP:SQL

Applies to: reported on Clarion 9 with SQL Server.

Problem

A stored procedure returns 1 if a SELECT finds records and 0 if not. It works in Management Studio. The Clarion code used BIND('retval',...), a call string beginning &retval=[dbo].[sp_...], {PROP:SQL} on a dummy string and NEXT. The profiler showed the call running, but the value did not reach a variable.

Solution

  1. End the procedure with a SELECT of the value to return, for example SELECT 1 FROM ... WHERE ... (John S., Liam).
  2. Call it with CALL and brackets around the parameters, then NEXT on the same dummy string: app:SQL=' CALL sp_TicketEntry_CheckDuplicateTicket(' & FPTICK:TicketKey & ', <39>' & FORMAT(FPTICK:TickLoadDate,D010-) & '<39>);' (the date picture there takes a leading at sign in Clarion). The first field of the returned row holds the value.
  3. Check ERRORCODE() after the PROP:SQL assignment and show FILEERROR() before NEXT (Liam).
  4. For output parameters or a true return value, read the help's MSSQL Accelerator section "Calling a Stored Procedure" (Jane F.). Use NORESULTCALL when the procedure returns no data set; CALL is described in that chapter (Arnor B.).

Caveats

  • Liam prefers returning 'True' and 'False' to 0, so a missing answer shows the procedure failed.
  • Liam advised against naming procedures sp_..., a prefix reserved for system procedures with a small cost. Edvard K. found MSSQL responds better to the D12 date picture than D010-.
  • If the date column is datetime, cast it to DATE to drop the time (John S.).
  • The poster wrote "Simple return values are working", without saying which suggestion helped.

Today (2026)

Not re-tested. SELECT plus CALL is plain PROP:SQL use and likely still works.

Sources: Kevin G. (Feb 2016, the question), John S., Liam, Jane F., Arnor B., Edvard K. (Feb 2016) in softvelocity.clarion.databasedrivers.