Solved

Indirect field reference in SQL statement:  Possible??

Posted on 2002-03-05
5
1,666 Views
Last Modified: 2008-02-26
WITHOUT using VBA and only using Access 2000, can I create a two-table query where the contents of a one field in one table can become the column name or field name in another.

TableOne has the following fields:
Field1 Text   10
Field2 Text   10
Field3 Text   10

TableTwo has one record and one field:
FieldName Text  10    <-  Holds the value "Field2"

I want to select only Field2 from table one.  I've tried the Eval() function without success:

select eval([TableTwo]![FieldName]) from TableOne

Thanks - gene
0
Comment
Question by:genehead
5 Comments
 
LVL 54

Expert Comment

by:nico5038
ID: 6842806
Don't think so, but perhaps another expert knows how to fool the access SQL interpreter...

Remains my Q: Why ?

Nic;o)
0
 
LVL 1

Expert Comment

by:S2
ID: 6842852
do you mean like this?
SELECT (SELECT tbl2.fld1 FROM tbl2) FROM tbl1;

this would give you the value of tbl2.fld1 the number of records you have in tbl1.

if you need the values of tbl1 that are in the field that has the name in tbl2.fld1 then you will have to compose it in VBA, there is no escaping it.
0
 
LVL 1

Expert Comment

by:matthewroberts
ID: 6843265
Why don't you want to code in VBA and build the sql string on the fly??
0
 
LVL 3

Accepted Solution

by:
pbryan earned 50 total points
ID: 6843559
you could do it with a couple of queries, but like nico says "why?"

--------------------

Query 1:

Union all the fields together
Select "Field1" as FieldName, Field1 as FieldValue from TableOne UNION Select "Field2" as FieldName, Field2 as FieldValue from TableOne UNION Select "Field3" as FieldName, Field3 as FieldValue from TableOne

Query2:
Join union query to TableTwo on fieldname column (this filters the columns)

Query3:
Create crosstab based on Query 2, use FieldName as column header
0
 
LVL 1

Author Comment

by:genehead
ID: 6847945
Accepting pbryan's comment as answer.  This is then kind of solution I was looking for.  I thought of UNION but didn't take it to the crosstab stage.  Good thinking pbryan.  Thanks - Gene
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now