on 2021 Jun 05 6:55 AM
CREATE PROCEDURE "DBA"."Z_calltable"( IN @table_name char(128) ) RESULT( "column_name" char(128) ) BEGIN select * from @table_name END;
How to make the table name passed as a variable in the stored procedure of the database
With v17, use indirect identifiers and/or TABLE REFs. They are precisely meant for such tasks to avoid the need for EXECUTE IMMEDIATE.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Volker Barth, thanks for the hint of indirect identifierst, but I get a syntax error while executing this code (SQL Anywhere 17):
CREATE OR REPLACE VARIABLE t_owner LONG VARCHAR = 'GROUPO';
CREATE OR REPLACE VARIABLE t_name LONG VARCHAR = 'Employees';
SELECT * FROM '[t_owner]'.'[t_name]';
Use back quotes like it says in the SAP Help Portal.
CREATE OR REPLACE VARIABLE t_owner LONG VARCHAR = 'GROUPO'; CREATE OR REPLACE VARIABLE t_name LONG VARCHAR = 'Employees'; SELECT * FROM `[t_owner]`.`[t_name]`;
IMO it's time to stop using the HTML Help because it's wrong wrong wrong:
Specify indirect identifiers in statements by enclosing them in square brackets and back quotes (for example, '[@myVariable]'), ...
Note that it SAYS back quotes BUT USES ordinary single quotes in all the example code.
The SAP Help Portal GETS IT RIGHT https://help.sap.com/viewer/93079d4ba8e44920ae63ffb4def91f5b/17.0/en-US/ce224c029e8c482c9fb637f5df3d...:
Specify indirect identifiers in statements by enclosing them in square brackets and back quotes (for example, `[@myVariable]`), ...
FWIW DCX is saying "This site can’t be reached dcx.sap.com took too long to respond."
IMO SAP should retire DCX and apply the savings to other areas of SQL Anywhere.
Oh, thank you. It works now!!
The snippet I have copied from http://dcx.sap.com/ but did not read the explanation of the syntax!
Yes HTML sometimes spoins codes!!
It's time to stop using the HTML Help because it's wrong wrong wrong:
Well, I don't know whether DCX is still actively used by the SQL Anywhere Doc Team – particularly by Jack –, but then again, corrections are explained there as comment, how do you get them within the SAP Help Portal for corrections after 17.0.4? (In other words: Do you know the release of the SQL Anywhere Help?)
(see the key that has the tilde ~)
FWIW, that's not necessarily true for non-English keyboard layouts...
By "HTML Help" I mean SQL-Anywhere-17-en.chm not DCX.
I can't get DCX to work any more, unless I use a browser that will accept an explicit http: in the URL. Chrome doesn't, and https://dcx.sap.com times out... for me 🙂
> Do you know the release of the SQL Anywhere Help?
No, but I'm pretty sure there's nothing more up to date than the SAP Help portal. The PDF cover pages I checked say Document Version: 17 – 2020-12-11 which is four years more recent than 17.0.4 🙂
The bottom line is, maintaining DCX is a complete and absolute waste of valuable resources. The world doesn't need two different websites describing exactly the same product.
Use EXECUTE IMMEDIATE but you may need to protect against SQL injection
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Add the WITH RESULT SET ON clause, and it certainly does work, so your claim is not correct.
Thanks @volker Barth
User | Count |
---|---|
66 | |
11 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.