We are using PB17 and SQLAnywhere 17
We have a generalized routine whereby we can pass a SQL query which takes one argument.
The problem is that some queries need to reference the same argument more than once.
As we understand it - if you use the ? argument placeholder more than once - the system assumes as separate argument associated with each occurrance of the argument - hence the follwing fails
SELECT metadatavalue from propmetadata where metadatatypecd = 'SHORTSYNOPSIS' AND propassetid in (SELECT propassetid from propasset where propno = (left(?, 8) + 'S00') AND langcd = SUBSTRING(?, 16, 3) AND langusecd = SUBSTRING(?, 20, 3))
where the following single parameter reference works
SELECT metadatavalue from propmetadata where metadatatypecd = 'SHORTSYNOPSIS' AND propassetid in (SELECT propassetid from propasset where propno = (left(?, 8) + 'S00')
We tried the following (noted as working in other database implementations) - which also doesnt work.
SELECT metadatavalue from propmetadata where metadatatypecd = 'SHORTSYNOPSIS' AND propassetid in (SELECT propassetid from propasset where propno = (left(?1, 8) + 'S00') AND langcd = SUBSTRING(?1, 16, 3) AND langusecd = SUBSTRING(?1, 20, 3))
Is there any way to do this in a straightforward manner??
Thanks
Glenn Barber
I tried something similar where using a derived value from the parameter and using that in the WHERE clause (seem to only work in SQL Anwhere) - However for some reason, it didnt work in the dynamic SQL
We were able to get it to work by creating a smart view which eliminated the complexity fo the query.
However the jury is still out whether there is a supported way to reference the same parameter more than once.