Dynamically Get Values by Table Names

Question

I have 3 tables, as shown below. Table A stores table names.

Table A:
ID TableName
01 B
02 C
03 B

 

Table B:
ID Num
01 13
02 14
03 15

 

Table C:
ID Num
01 91
02 92
03 93

According to table A’s ID values, I want the following output:
ID Num
01 13
02 92
03 15
Is there any way of doing this? Thanks.

 

Answer

Your task is to find the value in table B or table C according to table A’s each record. It’s easy to write it dynamically in SPL (Structured Process Language):

A

1

=connect("test")

2

=A1.query("select *   from A")

3

=A2.new(ID,   A1.query("select VAL from"+TABLENAME+"where ID   ="+ID).VAL:val)

A1: Connect to the database.

A2: Retrieve data from table A and return it as a table sequence.

A3: Dynamical compose a SQL statement to make the query according to the TableNamevalue in each of A2’s record.

A1

undefined

A2

undefined