How do I get values based on Field name?

G

Guest

I need to get values by entering only the field name in query.

Ex..In a Student table, the fields are like
RNo,Name,English,Maths,Science,.etc

I want to get the values by typing only the field names (Name & any suject
name) which shall show the values of Name & Subject.

If anyone can answer, would be helpfull me lot...

Thanks in advance.

Govind.
 
M

Michel Walsh

That is far from performing, not at all consistent with the basic idea of a
database, but you can try something like:


SELECT SWITCH( param='RNO', RNO,
param='Name', Name,
param='Maths', Math,
param='Science', Science,
... , ... )
FROM myTable



Vanderghast, Access MVP
 
G

Guest

Dear Michel,
Thanks for your answer.

But...Is there any other way to get data as i said.

Pls.revert .

Thnx...in advance...
 
M

Michel Walsh

With the suggested parameter query, you supply one field name, as parameter,
and the query returns the values under that field name.

If you need many fields, maybe it is better to write a string that represent
the SQL statement, like:


Dim str AS string
str= "SELECT " & listOfFieldsNameDelimitedByComa & " FROM tableName
"

and use that string as rowsource of a listbox, as example, or open a
recordset based on that string.



Hoping it may help,
Vanderghast, Access MVP
 
J

Jamie Collins

Dear Michel,
Thanks for your answer.

But...Is there any other way to get data as i said.

What Michel is trying to say is that you have serious design problems;
a classic case of bad SQL DML being indicative of bad SQL DDL. Think
about why you need a kludge to achieve this task.

Jamie.

--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top