G
garrett.berneche
I have a table(A) with a field (foreignFieldName) that holds the name of field in another table (B) and I want to build a Query/Subquery that returns the value of B.foreignFieldName for every entry in A. I would prefer doingthis in a native SQL way (a saved query) and avoid writing VBA code to iterate the data.
A
ID BID foreignFieldName
1 3 Length
2 2 Width
3 1 Height
B
ID Length Width Height
1 14 15 16
2 17 18 19
3 20 21 22
Desired ResultSet
ID Value
1 20
2 18
3 16
I have the following SQL right now -
SELECT A.ID,
"SELECT " + [A].[foreignFieldName] + " FROM B WHERE ID=" + Cstr([A].[ID]) FROM A;
Bad news, this puts an SQL string in ResultSet.Value. Good news, it is a well formed and ready to execute SQL string that looks like it would providethe correct result, if only it would execute.
I have also tried the following SQL
SELECT A.ID,
(SELECT A.foreignFieldName FROM B WHERE B.ID=A.ID) AS Value FROM A;
Sadly, this returns a copy of the A table - it evalutes A.foreignFieldName as a static string instead of a field name.
Does anyone know how I can accomplish my goal?
A
ID BID foreignFieldName
1 3 Length
2 2 Width
3 1 Height
B
ID Length Width Height
1 14 15 16
2 17 18 19
3 20 21 22
Desired ResultSet
ID Value
1 20
2 18
3 16
I have the following SQL right now -
SELECT A.ID,
"SELECT " + [A].[foreignFieldName] + " FROM B WHERE ID=" + Cstr([A].[ID]) FROM A;
Bad news, this puts an SQL string in ResultSet.Value. Good news, it is a well formed and ready to execute SQL string that looks like it would providethe correct result, if only it would execute.
I have also tried the following SQL
SELECT A.ID,
(SELECT A.foreignFieldName FROM B WHERE B.ID=A.ID) AS Value FROM A;
Sadly, this returns a copy of the A table - it evalutes A.foreignFieldName as a static string instead of a field name.
Does anyone know how I can accomplish my goal?