Choose a Table at the Run Time:
I have seen this peculiar problem where people are asking to choose the Table at the run Time. First time if you think about this, it seems very odd, why there is such a requirement to do that.
I have found a way to do that and I want to share this today.
Lets say I have Table Finance (FI), Accounts Payable(AP) and Accounts Receivable(AR). All these tables have the same columns and the data types. At the Run Time User want to see the data either from Table FI, AP or AR.
So these tables have the same columns and they should get the prompt at the run time to select the data from FI, AP or AR Table.
To achieve this scenario, first create a derived table with the Union of these tables.
Select FI as Table_Name, Account, Type, Sales from Table_FI
where 'FI' = @prompt('Select Table','A',{'FI','AP','AR'},mono,constrained)
Union ALL
Select AP as Table_Name, Account, Type, Sales from Table_AP
where 'AP' = @prompt('Select Table','A',{'FI','AP','AR'},mono,constrained)
Union ALL
Select AR as Table_Name, Account, Type, Sales from Table_AR
where 'AR' = @prompt('Select Table','A',{'FI','AP','AR'},mono,constrained)
With this definition of the derive table , we will have four columns with the following result set.
With the report created on top of such s derive table, the User will get a prompt to Select Table with list of values FI, AP & AR. These are the dummy values which defines what table to select at the run time.
When User select the value FI, first 2 rows will be shown in the result, for AP 3 & 4 rows will be shown and for AR, last 2 rows will be shown in the report.
I have shown this technique for one table which can be scaled to implement with a large set of tables which are joined with one another. In that situation all the tables first need to have a individual derive table with the Union ALL conditions. One Derive table can have the @prompt condition and that should drive to filter the data from the rest of the tables which are joined with this derive Table. Also we need to use the Table_Name in the join conditions as well.
This technique can also be implemented in IDT where your Tables are stored in multiple databases.
I hope you enjoy this
I have seen this peculiar problem where people are asking to choose the Table at the run Time. First time if you think about this, it seems very odd, why there is such a requirement to do that.
I have found a way to do that and I want to share this today.
Lets say I have Table Finance (FI), Accounts Payable(AP) and Accounts Receivable(AR). All these tables have the same columns and the data types. At the Run Time User want to see the data either from Table FI, AP or AR.
| Finance (FI) |
| Accounts Payable (AP) |
| Accounts Receivable (AR) |
To achieve this scenario, first create a derived table with the Union of these tables.
Select FI as Table_Name, Account, Type, Sales from Table_FI
where 'FI' = @prompt('Select Table','A',{'FI','AP','AR'},mono,constrained)
Union ALL
Select AP as Table_Name, Account, Type, Sales from Table_AP
where 'AP' = @prompt('Select Table','A',{'FI','AP','AR'},mono,constrained)
Union ALL
Select AR as Table_Name, Account, Type, Sales from Table_AR
where 'AR' = @prompt('Select Table','A',{'FI','AP','AR'},mono,constrained)
With this definition of the derive table , we will have four columns with the following result set.
| Derive Table |
When User select the value FI, first 2 rows will be shown in the result, for AP 3 & 4 rows will be shown and for AR, last 2 rows will be shown in the report.
I have shown this technique for one table which can be scaled to implement with a large set of tables which are joined with one another. In that situation all the tables first need to have a individual derive table with the Union ALL conditions. One Derive table can have the @prompt condition and that should drive to filter the data from the rest of the tables which are joined with this derive Table. Also we need to use the Table_Name in the join conditions as well.
This technique can also be implemented in IDT where your Tables are stored in multiple databases.
I hope you enjoy this