 |
| Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

December 17th, 2003, 02:16 PM
|
|
Authorized User
|
|
Join Date: Sep 2003
Posts: 83
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
A SQL question
Hi everyone,
USing access, I try to run the following SQL:
SELECT (Select Value from AnotherTable) FROM MyQuery
MyQuery returns a set of data and I want to filter it further by selecting only the records that are returned by the sub-select. However, this does not work. Are such select queries illegal. Is it not possible to tell it the column names for select through another select query?
Thanks,
Pankaj
|
|

December 17th, 2003, 04:41 PM
|
|
Registered User
|
|
Join Date: Dec 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Try this kind of statement
SELECT Table1.a, Table1.x, Table1.y FROM Table1
WHERE (Table1.x IN (SELECT Table2.x FROM Table2));
Regards,
Raul
|
|

December 17th, 2003, 05:13 PM
|
|
Authorized User
|
|
Join Date: Sep 2003
Posts: 83
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi there,
Actually here is a more clear description of what I am trying to do. Sorry to be vague earlier.
In a Select statement you can specify the columns that you want to display.
Example,
Select FirstName, LastName from PeopleTable.
What I am trying to do is this: I have a table (say PeopleTable) that has many columns...say LastName, FirstName, Data Of Birth, Occupation etc.
Now, I have another table that is filled by another process that tells me which columns to display: say, example, LastName, FirstName...
So what I wanted to do was:
SELECT (Select Values from AnotherTable) FROM PeopleTable
Select Values from AnotherTable would return LastName and FirstName and my query would be:
SELECT(LastName, FirstName) from PeopleTable. However, I guess SQL does not do such syntactic substitution.
Does anyone know a way to achieve this. I do not want to use a string and concatenate each of the choices, if there is a way to achieve this with SQL.
Thanks a lot
Sincerely,
Pankaj
|
|

December 17th, 2003, 07:01 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 308
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
You'd have to turn to VBA for that. For example, you could create a recordset which goes through the records in your "AnotherTable" and creates a SQL statement from that, something along the lines of (and I've not tested this)....
Code:
Dim strSQL as String, rst as DAO.Recordset
strSQL = "SELECT "
set rst= CurrentDB.OpenRecordset("SELECT Field From AnotherTable")
rst.MoveFirst
While not rst.EOF
strSQL = strSQL & rst("Field") & ", "
rst.MoveNext
Wend
strSQL = Left(strSQL, Len(strSQL)-2)'Get rid of the trailing comma and space
strSQL = strSQL & " FROM PeopleTable"
Dim qdf as QueryDef
Set qdf = CurrentDB.CreateQueryDef("YourQuery", strSQL)
Steven
I am a loud man with a very large hat. This means I am in charge
(edited due to obvious typo)
|
|

December 17th, 2003, 08:27 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 625
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
It looks like you have to join your results and query those results sets. Do both tables have the similar data? Is the source of your second table the same as the first?
|
|

December 5th, 2005, 04:37 PM
|
|
Registered User
|
|
Join Date: Dec 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
jemacc is right!!!
<h1>prasad veluri</h1>
http://prasad-veluri.com
<h1>Narasimha Prasad Veluri</h1>
|
Similar Threads
|
| Thread |
Thread Starter |
Forum |
Replies |
Last Post |
| SQL Question |
psnow1985 |
ASP.NET 2.0 Basics |
23 |
March 21st, 2008 11:48 AM |
| sql query question |
ldp101068 |
SQL Server 2000 |
6 |
December 3rd, 2007 03:41 PM |
| ASP / Sql question |
joebeem |
Classic ASP Basics |
0 |
August 28th, 2007 02:45 PM |
| Sql-question |
boson |
SQL Language |
2 |
July 3rd, 2004 06:39 AM |
| SQL question |
U.N.C.L.E. |
SQL Server 2000 |
3 |
October 10th, 2003 02:00 PM |
|
 |