Database Management
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesDatabase Management

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 16th, 2003, 01:56 AM
ngibsonau ngibsonau is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 138 ngibsonau User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Calling Access query with parameters from another Query

It may sound like a stupid thing to want to do but I'm trying to call a Access Database query from another query and also pass the second query a paramter, which is possibly a parameter to the first.

I don't want a solution for any other type of database. I'm interested in the limitations of Access only.

If i have a query

Code:
select name from tblperson where id = [x]


I can type in x when propted by access when run through Access gui.

I can also use VB or ASP and ADO to run a command which calls
using "exec query" and setting a parameter for "x"

But in a query you are not able to call "exec"

Does anybody know a pure Access sql solution to this problem, I don't even want to use a access/VBA module.
__________________
--

ngibsonau

Reply With Quote
  #2  
Old June 16th, 2003, 09:44 AM
ecit12's Avatar
ecit12 ecit12 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 411 ecit12 User rank is Corporal (100 - 500 Reputation Level)ecit12 User rank is Corporal (100 - 500 Reputation Level)ecit12 User rank is Corporal (100 - 500 Reputation Level)ecit12 User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 2 Days 12 h 42 m 14 sec
Reputation Power: 7
if the first query is in the same DB as the second DB, it should be simple.

Just type

Select Query1.fieldName
from Query1;

forgot how to make it ask u for a parameter..

Reply With Quote
  #3  
Old June 16th, 2003, 10:28 AM
dschroth dschroth is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Cobalt, CT
Posts: 11 dschroth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to dschroth
I'm not 100% clear on what you want to do, but it seems to me you are trying to use a parameter (possibly several times) without being prompted for the parameter or writing code.

One work-around I have used is to create a table or view which returns one record to store the parameter. An update statement can then set the parameter, and then by joining that table or view into your query you can easily apply that parameter to any queries you need to run.

Reply With Quote
  #4  
Old June 16th, 2003, 08:23 PM
ngibsonau ngibsonau is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 138 ngibsonau User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
That sounds like the best work around I have heard so far.

I'll give it a try. It's a shame Access Queries seem to be crippled in that you cant pass them parameters no matter where you call them from.

I'm still open to any other suggestions.

Here is a little more detail so everbody is on the same wavelength

If you call the query I gave before the name qn (here again for convenience)

Query: qn
Code:
select name from tblperson where id = [x]


and try to call it from a query named q1, how do I pass a value for [x] in qn?

Query:q1
Code:
SELECT [name] FROM qn;


With the above query the user interface asks for x to be input

the following don't work, where I'm trying to give x the value of 4
Code:
SELECT [name] FROM qn(4);


The above fails i nthe where clause

Code:
SELECT [name] FROM qn[4];


The above fails i nthe where clause also

Code:
SELECT [name] FROM qn where qn.x =4;


The above ask for input for x and qn.x via the user interface.

Code:
exec qn 4


and

Code:
exec qn(4)


both fail because exec is not allowed.

Finally what I really want to be able to do is pass the value of the parameter [y] from the first query to qn as [x]
Code:
SELECT [name] FROM qn([y]);


I will post code code that emulates the process as suggested by dschroth using tempory tables etc. when I get a chance. But again don't let that stop anybody from doing the same.

Reply With Quote
  #5  
Old June 16th, 2003, 09:33 PM
dschroth dschroth is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Cobalt, CT
Posts: 11 dschroth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to dschroth
I guess you also know about MSDE, which is basically a free version of MS SQL that Access can use as a backend database. If you use an MSDE database you can do what you want with a stored procedure and EXEC.

Reply With Quote
  #6  
Old June 16th, 2003, 10:19 PM
ngibsonau ngibsonau is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 138 ngibsonau User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Take a look at my first post. I know about other databases, I'm only interested in the cababilities or lack thereof Access and the jet engine, in so much as what I can do in SQL in an access MDB without any non SQL programming, no VBA, no MySql, no Oracle, no stored procedures (unless you can implement a stored procedure in ACCESS). I can do what I want in Access with about ten lines of VB code, but thats not the point.

Which brings up an interesting point.( To give this post a purpose, more than a plain flame)

In access you can go
Code:
PARAMETERS x IEEEDouble;
SELECT [tblname].[name]
FROM tblname
WHERE id=x;


which seems equivalent to
Code:
select name from tblname where id = [x];

as far as I can tell except what looks like a slightly more type safe input???

Can anybody give me more clues about this syntax? is it old and outdate/undocumented?

To complement this there is also
Code:
PROCEDURE qaa;
select name from tblname where id = [x];


Does the procedure statement and its parameter qaa actually do anything? For me the query name is given when saving the query in the access gui which doesn't have to be the same as that given in the query body? Does anybody know how to use this properly. I can't seem to mix the PARAMETERS and PROCEDURE statements and get a query that works!

Reply With Quote
  #7  
Old September 30th, 2003, 10:30 AM
jwildman jwildman is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 3 jwildman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
ok this is way too simple but here goes..

Look at this sample function from one of my vbscripts.

function SelectJob()
Dim MyConn, SQL, RS
Set MyConn=CreateObject("ADODB.Connection")
MyConn.Open "Driver={Microsoft Access Driver (*.mdb)}; DBQ=d:\sample.mdb"
Rjobno = InputBox("Job Number To Display?",JobNo)
SQL = "Delete * From Requests Where Jobno='"&Rjobno&"'"
Set RS=MyConn.Execute(SQL)
Alert("Record Deleted")
end function

Rjobno = InputBox("Job Number To Display?",JobNo)
this prompts the user for a jobnumber

SQL = "Delete * From Requests Where Jobno='"&Rjobno&"'"
this applies the variable Rjobno to the sql query

so this function prompts the user for a jobnumber then builds and executes the sql to delete the corresponding row from the Requests table in the database d:\sample.mdb.

Jim Wildman

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesDatabase Management > Calling Access query with parameters from another Query


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway