In Firebird, I can do the following: SELECT * FROM TABLE AS A LEFT JOIN SP_CALC( A.COL1 ) AS B ON( 1 = 1 ) This will take the input TABLE.COL1 and return a result list of both table A columns and Stored Procedure B Columns. Have attempted wothout success to the same in sqlAnywhere. Using SQL Anywhere 12. Any Ideas. asked 04 Sep '15, 02:49 LoganTennis |
You can use a "lateral procedure call" to do so, something like
See lateral derived tables in the v12.0.1 docs... answered 04 Sep '15, 03:26 Volker Barth 1
Be aware that lateral works like an INNER JOIN and not a LEFT JOIN as was the question.
The result is:
So if you want a LEFT JOIN you have to make sure the procedure always has a result set
then the result is:
(04 Sep '15, 07:01)
Christian Ha...
Replies hidden
Good catch!
(04 Sep '15, 07:27)
Volker Barth
|
Here's a better solution when a left join is required by using the OUTER APPLY operator (which I tend to overlook... - here's a great article, originally from Glenn Paulley): create table t1 ( id integer ); insert into t1 (id) values (1); insert into t1 (id) values (2); create procedure Test (IN pId integer) result (descr varchar(3)) begin if pId = 1 then select 'abc'; endif end; select * from t1 cross apply test(t1.id); -- returns -- 1, 'abc' select * from t1 outer apply test(t1.id) -- returns -- 1, 'abc' -- 2, null Apparently, OUTER APPLY does not require that the stored procedure returns a NULL value for missing data. answered 08 Sep '15, 06:29 Volker Barth |
@OtherPeople: The issue for SQL Anywhere is not so much the LEFT OUTER JOIN, it is the use of a column as an argument (which Volker covers in his replies).
According to the Firebird FAQ "How to JOIN a table and selectable stored procedure?" the LEFT JOIN is a requirement when joining a table with a stored procedure call that refers to a column from the table as an argument; i.e., Firebird does not allow for an INNER JOIN... which may in fact be what you want rather than a bunch of NULL values.
Here's the Firebird FAQ, complete with speling misteak and hokey "so they are available" justification :)...