<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Question Re: indirect identifier within sql statement in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/indirect-identifier-within-sql-statement/qaa-p/13835924#M4866767</link>
    <description>&lt;P&gt;Thanks for the replies and hints, it has worked after adding a help procedure like this:&lt;/P&gt;
&lt;PRE&gt;create or replace procedure MyHelpProc(table_name varchar(100), col_name varchar(100))
result (myres varchar(100))
begin
select list(`[col_name]`) from `[table_name]`;
end;
----
select (select * from MyHelpProc(fieldtable, fieldname)), fieldname, fieldtable, hinttext from mystructure
&lt;/PRE&gt;</description>
    <pubDate>Tue, 12 Sep 2023 15:58:46 GMT</pubDate>
    <dc:creator>Baron</dc:creator>
    <dc:date>2023-09-12T15:58:46Z</dc:date>
    <item>
      <title>indirect identifier within sql statement</title>
      <link>https://community.sap.com/t5/technology-q-a/indirect-identifier-within-sql-statement/qaq-p/13835923</link>
      <description>&lt;P&gt;I have the following 3 tables with contents as follows:&lt;/P&gt;
&lt;PRE&gt;create or replace table mystructure (fieldname varchar(100), fieldtable varchar (100), hinttext varchar (100));
create or replace table mydata1 (dataindex1 int, datacontent1 varchar(100));
create or replace table mydata2 (dataindex2 int, datacontent2 varchar(100));

insert into mystructure values 
('datacontent1', 'mydata1', 'hint1'),
('datacontent2', 'mydata2', 'hint2');

insert into mydata1 
values (1, 'data1_1'),
values (2, 'data1_2'),
values (3, 'data1_3');

insert into mydata2
values (1, 'data2_1'),
values (2, 'data2_2'),
values (3, 'data2_3');
&lt;/PRE&gt;

&lt;P&gt;Why I get a syntax error while executing this select statement?
&lt;/P&gt;&lt;PRE&gt;select 
(select list('[fieldname]') from '[fieldtable]'),
* from mystructure
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;
&lt;P&gt;What I want to get is a list of available values of both tables &lt;STRONG&gt;mydata1&lt;/STRONG&gt; &amp;amp; &lt;STRONG&gt;mydata2&lt;/STRONG&gt; besides the main table &lt;STRONG&gt;mystructure&lt;/STRONG&gt;, so something like this:
&lt;/P&gt;&lt;PRE&gt;'data1_1,data1_2,data1_3';'datacontent1';'mydata1';'hint1'
'data2_1,data2_2,data2_3';'datacontent2';'mydata2';'hint2'
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Sep 2023 11:32:03 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/indirect-identifier-within-sql-statement/qaq-p/13835923</guid>
      <dc:creator>Baron</dc:creator>
      <dc:date>2023-09-11T11:32:03Z</dc:date>
    </item>
    <item>
      <title>Re: indirect identifier within sql statement</title>
      <link>https://community.sap.com/t5/technology-q-a/indirect-identifier-within-sql-statement/qaa-p/13835925#M4866768</link>
      <description>&lt;P&gt;Indirect iedentifiers require back quotes, not single quotes. Compare this &lt;A href="https://sqlanywhere-forum.sap.com/questions/36975"&gt;older FAQ&lt;/A&gt; you may remember...&lt;/P&gt;
&lt;P&gt;If you want to select data from several known tables with compatible schema, a UNION ALL might also do the trick.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Sep 2023 11:41:02 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/indirect-identifier-within-sql-statement/qaa-p/13835925#M4866768</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2023-09-11T11:41:02Z</dc:date>
    </item>
    <item>
      <title>Re: indirect identifier within sql statement</title>
      <link>https://community.sap.com/t5/technology-q-a/indirect-identifier-within-sql-statement/qaa-p/13835926#M4866769</link>
      <description>&lt;P&gt;Thanks for the hint, but even with backtick I get a syntax error:&lt;/P&gt;
&lt;PRE&gt;select 
(select list(`[fieldname]`) from `[fieldtable]`),
* from mystructure
&lt;/PRE&gt;</description>
      <pubDate>Mon, 11 Sep 2023 13:21:02 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/indirect-identifier-within-sql-statement/qaa-p/13835926#M4866769</guid>
      <dc:creator>Baron</dc:creator>
      <dc:date>2023-09-11T13:21:02Z</dc:date>
    </item>
    <item>
      <title>Re: indirect identifier within sql statement</title>
      <link>https://community.sap.com/t5/technology-q-a/indirect-identifier-within-sql-statement/qaa-p/13835927#M4866770</link>
      <description>&lt;P&gt;A result set column is not a variable and as such cannot be used as a reference to an indirect identifier.  I am not sure what syntax error you are encountering but I do get the error Variable 'fieldtable' not found. This is expected as that variable is not declared.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Sep 2023 17:25:05 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/indirect-identifier-within-sql-statement/qaa-p/13835927#M4866770</guid>
      <dc:creator>chris_keating</dc:creator>
      <dc:date>2023-09-11T17:25:05Z</dc:date>
    </item>
    <item>
      <title>Re: indirect identifier within sql statement</title>
      <link>https://community.sap.com/t5/technology-q-a/indirect-identifier-within-sql-statement/qaa-p/13835928#M4866771</link>
      <description>&lt;P&gt;In addition to Chris's statement, as you need variables as value for an indirect identifier, you need to supply the value "one by one", i.e. when using a table to supply the values, you need to do this on a per-row base.&lt;/P&gt;
&lt;P&gt;Here's a sample with a FOR statement that uses the contents of your "mystructure" table for each row as input for indirect identifiers.&lt;/P&gt;
&lt;PRE&gt;begin
   for forCrs as crs cursor for
      select fieldname, fieldtable from mystructure order by 1
   for read only
   do
      select list(`[fieldname]`) from `[fieldtable]`;
   end for;
end;
&lt;/PRE&gt;

&lt;P&gt;Note, the cursor does not use aliases for the column names but within the do/end for block, the names "fieldname" and "fieldtable" are not column names but the automatically declared cursor variables.
I could also have used aliases:
&lt;/P&gt;&lt;PRE&gt;begin
   for forCrs as crs cursor for
      select fieldname as varFieldname, fieldtable as varFieldtable from mystructure order by 1
   for read only
   do
      select list(&lt;CODE&gt;[varFieldname]&lt;/CODE&gt;) from &lt;CODE&gt;[varFieldtable]&lt;/CODE&gt;;
   end for;
end;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;
&lt;HR /&gt;
&lt;P&gt;Aside: The FOR statement does return the contents of each table separately, in contrast to your requirement. You might be able to use ARRAY-type variables to store a variable number of values for your use case.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Sep 2023 03:41:14 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/indirect-identifier-within-sql-statement/qaa-p/13835928#M4866771</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2023-09-12T03:41:14Z</dc:date>
    </item>
    <item>
      <title>Re: indirect identifier within sql statement</title>
      <link>https://community.sap.com/t5/technology-q-a/indirect-identifier-within-sql-statement/qaa-p/13835924#M4866767</link>
      <description>&lt;P&gt;Thanks for the replies and hints, it has worked after adding a help procedure like this:&lt;/P&gt;
&lt;PRE&gt;create or replace procedure MyHelpProc(table_name varchar(100), col_name varchar(100))
result (myres varchar(100))
begin
select list(`[col_name]`) from `[table_name]`;
end;
----
select (select * from MyHelpProc(fieldtable, fieldname)), fieldname, fieldtable, hinttext from mystructure
&lt;/PRE&gt;</description>
      <pubDate>Tue, 12 Sep 2023 15:58:46 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/indirect-identifier-within-sql-statement/qaa-p/13835924#M4866767</guid>
      <dc:creator>Baron</dc:creator>
      <dc:date>2023-09-12T15:58:46Z</dc:date>
    </item>
    <item>
      <title>Re: indirect identifier within sql statement</title>
      <link>https://community.sap.com/t5/technology-q-a/indirect-identifier-within-sql-statement/qaa-p/13835929#M4866772</link>
      <description>&lt;P&gt;That's a smart solution, methinks. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2023 04:01:05 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/indirect-identifier-within-sql-statement/qaa-p/13835929#M4866772</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2023-09-13T04:01:05Z</dc:date>
    </item>
    <item>
      <title>Re: indirect identifier within sql statement</title>
      <link>https://community.sap.com/t5/technology-q-a/indirect-identifier-within-sql-statement/qaa-p/13835930#M4866773</link>
      <description>&lt;P&gt;Actually working with array-type in SQL is (for me) always a difficult task, sothat switched to this solution (shorter and clearer).&lt;/P&gt;
&lt;P&gt;Thanks again.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2023 04:34:16 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/indirect-identifier-within-sql-statement/qaa-p/13835930#M4866773</guid>
      <dc:creator>Baron</dc:creator>
      <dc:date>2023-09-13T04:34:16Z</dc:date>
    </item>
  </channel>
</rss>

