473,778 Members | 1,852 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Save query return in variable

Hi. I would like to query a database, given several where clauses to refine
my search, and return the value of one single field in the database.

eg: I have a table that lists teachers. Their first name, last name, age,
unique teacher number, etc is in the file.

I want to return the unique teacher number, for example, of the teacher
whose first name is Jane and last name is Doe.

How does one do this?

Adrian
Jul 17 '05 #1
8 4814
select teacherid from tblteachers where firstname = 'Jane' and lastname =
'Doe'

greets John

"Adrian Parker" <ad***********@ NOSPAMsympatico .ca> schreef in bericht
news:1Z******** ************@ne ws20.bellglobal .com...
Hi. I would like to query a database, given several where clauses to refine my search, and return the value of one single field in the database.

eg: I have a table that lists teachers. Their first name, last name, age, unique teacher number, etc is in the file.

I want to return the unique teacher number, for example, of the teacher
whose first name is Jane and last name is Doe.

How does one do this?

Adrian

Jul 17 '05 #2

"John Lauwers" <no****@fictief .com> wrote in message
news:40******** *************@n ews.skynet.be.. .
select teacherid from tblteachers where firstname = 'Jane' and lastname =
'Doe'
Thank you.

Can I do that without making a new RecordSet variable? Storing the entire
recordset just to return one integer seems wasteful.

Ideally I want something like this:

Dim driverID as integer
driverID = 'Query here which returns the driverID for one record from
database'
Adrian
"Adrian Parker" <ad***********@ NOSPAMsympatico .ca> schreef in bericht
news:1Z******** ************@ne ws20.bellglobal .com...
Hi. I would like to query a database, given several where clauses to

refine
my search, and return the value of one single field in the database.

eg: I have a table that lists teachers. Their first name, last name,

age,
unique teacher number, etc is in the file.

I want to return the unique teacher number, for example, of the teacher
whose first name is Jane and last name is Doe.

How does one do this?

Jul 17 '05 #3
Yes you can make a function that will search your recordset and return the
id

Private function ReturnId(firstn ame as string,lastname as string) as long
dim rst as adodb.recordset
set rst = new adodb.recordset
with rst
.open "select teacherid from tblteachers where firstname = '" &
firstname "' and lastname = '" & lastname & "'", db, adOpenDynamic,
adLockReadOnly
if not .eof and not .bof then
.movefirst
returnid = .fields("teache rid").value
else
returid = 0 'no teacherid found
end if
.close
end with
set rst = nothing

end function

(PS function not tested)

Greets John

"Adrian Parker" <ad***********@ NOSPAMsympatico .ca> schreef in bericht
news:1Z******** ***********@new s20.bellglobal. com...

"John Lauwers" <no****@fictief .com> wrote in message
news:40******** *************@n ews.skynet.be.. .
select teacherid from tblteachers where firstname = 'Jane' and lastname = 'Doe'


Thank you.

Can I do that without making a new RecordSet variable? Storing the entire
recordset just to return one integer seems wasteful.

Ideally I want something like this:

Dim driverID as integer
driverID = 'Query here which returns the driverID for one record from
database'
Adrian
"Adrian Parker" <ad***********@ NOSPAMsympatico .ca> schreef in bericht
news:1Z******** ************@ne ws20.bellglobal .com...
Hi. I would like to query a database, given several where clauses to

refine
my search, and return the value of one single field in the database.

eg: I have a table that lists teachers. Their first name, last name,

age,
unique teacher number, etc is in the file.

I want to return the unique teacher number, for example, of the teacher whose first name is Jane and last name is Doe.

How does one do this?


Jul 17 '05 #4
Then off course you have to call the function

Dim driverID as long
driverID = ReturnId("Jane" ,"Doe")

greets John

"John Lauwers" <no****@fictief .com> schreef in bericht
news:40******** *************@n ews.skynet.be.. .
Yes you can make a function that will search your recordset and return the
id

Private function ReturnId(firstn ame as string,lastname as string) as long
dim rst as adodb.recordset
set rst = new adodb.recordset
with rst
.open "select teacherid from tblteachers where firstname = '" &
firstname "' and lastname = '" & lastname & "'", db, adOpenDynamic,
adLockReadOnly
if not .eof and not .bof then
.movefirst
returnid = .fields("teache rid").value
else
returid = 0 'no teacherid found
end if
.close
end with
set rst = nothing

end function

(PS function not tested)

Greets John

"Adrian Parker" <ad***********@ NOSPAMsympatico .ca> schreef in bericht
news:1Z******** ***********@new s20.bellglobal. com...

"John Lauwers" <no****@fictief .com> wrote in message
news:40******** *************@n ews.skynet.be.. .
select teacherid from tblteachers where firstname = 'Jane' and lastname
=
'Doe'


Thank you.

Can I do that without making a new RecordSet variable? Storing the entire
recordset just to return one integer seems wasteful.

Ideally I want something like this:

Dim driverID as integer
driverID = 'Query here which returns the driverID for one record from
database'
Adrian
"Adrian Parker" <ad***********@ NOSPAMsympatico .ca> schreef in bericht
news:1Z******** ************@ne ws20.bellglobal .com...
> Hi. I would like to query a database, given several where clauses

to refine
> my search, and return the value of one single field in the database.
>
> eg: I have a table that lists teachers. Their first name, last name, age,
> unique teacher number, etc is in the file.
>
> I want to return the unique teacher number, for example, of the

teacher > whose first name is Jane and last name is Doe.
>
> How does one do this?



Jul 17 '05 #5
"John Lauwers" <no****@fictief .com> wrote in message
news:40******** *************@n ews.skynet.be.. .
Yes you can make a function that will search your recordset and return the
id

Private function ReturnId(firstn ame as string,lastname as string) as long
dim rst as adodb.recordset
set rst = new adodb.recordset
with rst
.open "select teacherid from tblteachers where firstname = '" &
firstname "' and lastname = '" & lastname & "'", db, adOpenDynamic,
adLockReadOnly
if not .eof and not .bof then
.movefirst
returnid = .fields("teache rid").value
else
returid = 0 'no teacherid found
end if
.close
end with
set rst = nothing

But this will return the entire database into the recordset, and I
understand it, and then put the userID into returnID. That is not very
scallable if the database is very large.

Adrian

end function

(PS function not tested)

Greets John

"Adrian Parker" <ad***********@ NOSPAMsympatico .ca> schreef in bericht
news:1Z******** ***********@new s20.bellglobal. com...

"John Lauwers" <no****@fictief .com> wrote in message
news:40******** *************@n ews.skynet.be.. .
select teacherid from tblteachers where firstname = 'Jane' and lastname
=
'Doe'


Thank you.

Can I do that without making a new RecordSet variable? Storing the entire
recordset just to return one integer seems wasteful.

Ideally I want something like this:

Dim driverID as integer
driverID = 'Query here which returns the driverID for one record from
database'
Adrian
"Adrian Parker" <ad***********@ NOSPAMsympatico .ca> schreef in bericht
news:1Z******** ************@ne ws20.bellglobal .com...
> Hi. I would like to query a database, given several where clauses

to refine
> my search, and return the value of one single field in the database.
>
> eg: I have a table that lists teachers. Their first name, last name, age,
> unique teacher number, etc is in the file.
>
> I want to return the unique teacher number, for example, of the

teacher > whose first name is Jane and last name is Doe.
>
> How does one do this?



Jul 17 '05 #6
Try to search msdn for the execute command of a connection , that is maybe
what you are searching for

greets John
"Adrian Parker" <ad***********@ NOSPAMsympatico .ca> schreef in bericht
news:Z_******** ***********@new s20.bellglobal. com...
"John Lauwers" <no****@fictief .com> wrote in message
news:40******** *************@n ews.skynet.be.. .
Yes you can make a function that will search your recordset and return the
id

Private function ReturnId(firstn ame as string,lastname as string) as long dim rst as adodb.recordset
set rst = new adodb.recordset
with rst
.open "select teacherid from tblteachers where firstname = '" &
firstname "' and lastname = '" & lastname & "'", db, adOpenDynamic,
adLockReadOnly
if not .eof and not .bof then
.movefirst
returnid = .fields("teache rid").value
else
returid = 0 'no teacherid found
end if
.close
end with
set rst = nothing

But this will return the entire database into the recordset, and I
understand it, and then put the userID into returnID. That is not very
scallable if the database is very large.

Adrian

end function

(PS function not tested)

Greets John

"Adrian Parker" <ad***********@ NOSPAMsympatico .ca> schreef in bericht
news:1Z******** ***********@new s20.bellglobal. com...

"John Lauwers" <no****@fictief .com> wrote in message
news:40******** *************@n ews.skynet.be.. .
> select teacherid from tblteachers where firstname = 'Jane' and

lastname
=
> 'Doe'

Thank you.

Can I do that without making a new RecordSet variable? Storing the

entire recordset just to return one integer seems wasteful.

Ideally I want something like this:

Dim driverID as integer
driverID = 'Query here which returns the driverID for one record from
database'
Adrian

> "Adrian Parker" <ad***********@ NOSPAMsympatico .ca> schreef in bericht > news:1Z******** ************@ne ws20.bellglobal .com...
> > Hi. I would like to query a database, given several where clauses to > refine
> > my search, and return the value of one single field in the database. > >
> > eg: I have a table that lists teachers. Their first name, last name, > age,
> > unique teacher number, etc is in the file.
> >
> > I want to return the unique teacher number, for example, of the

teacher
> > whose first name is Jane and last name is Doe.
> >
> > How does one do this?



Jul 17 '05 #7
Like:

db.execute(DELE TE from SomeTable Where someThing = SomeOtherThing. ...

I think .execute() just covers Action Queries to Access does it not? I'll
check MSDN, which I don't own, at school tomorrow.

I just have student edition of VB, which has no MSDN.

Adrian
"John Lauwers" <no****@fictief .com> wrote in message
news:40******** *************@n ews.skynet.be.. .
Try to search msdn for the execute command of a connection , that is maybe
what you are searching for

greets John
"Adrian Parker" <ad***********@ NOSPAMsympatico .ca> schreef in bericht
news:Z_******** ***********@new s20.bellglobal. com...
"John Lauwers" <no****@fictief .com> wrote in message
news:40******** *************@n ews.skynet.be.. .
Yes you can make a function that will search your recordset and return the id

Private function ReturnId(firstn ame as string,lastname as string) as long dim rst as adodb.recordset
set rst = new adodb.recordset
with rst
.open "select teacherid from tblteachers where firstname = '" & firstname "' and lastname = '" & lastname & "'", db, adOpenDynamic,
adLockReadOnly
if not .eof and not .bof then
.movefirst
returnid = .fields("teache rid").value
else
returid = 0 'no teacherid found
end if
.close
end with
set rst = nothing

But this will return the entire database into the recordset, and I
understand it, and then put the userID into returnID. That is not very
scallable if the database is very large.

Adrian

end function

(PS function not tested)

Greets John

"Adrian Parker" <ad***********@ NOSPAMsympatico .ca> schreef in bericht
news:1Z******** ***********@new s20.bellglobal. com...
>
> "John Lauwers" <no****@fictief .com> wrote in message
> news:40******** *************@n ews.skynet.be.. .
> > select teacherid from tblteachers where firstname = 'Jane' and

lastname
=
> > 'Doe'
>
> Thank you.
>
> Can I do that without making a new RecordSet variable? Storing the

entire
> recordset just to return one integer seems wasteful.
>
> Ideally I want something like this:
>
> Dim driverID as integer
> driverID = 'Query here which returns the driverID for one record from > database'
>
>
> Adrian
>
>
>
> > "Adrian Parker" <ad***********@ NOSPAMsympatico .ca> schreef in bericht > > news:1Z******** ************@ne ws20.bellglobal .com...
> > > Hi. I would like to query a database, given several where
clauses
to
> > refine
> > > my search, and return the value of one single field in the

database. > > >
> > > eg: I have a table that lists teachers. Their first name, last

name,
> > age,
> > > unique teacher number, etc is in the file.
> > >
> > > I want to return the unique teacher number, for example, of the
teacher
> > > whose first name is Jane and last name is Doe.
> > >
> > > How does one do this?
>
>



Jul 17 '05 #8

"Adrian Parker" <ad***********@ NOSPAMsympatico .ca> wrote in message
news:Z_******** ***********@new s20.bellglobal. com...
"John Lauwers" <no****@fictief .com> wrote in message
news:40******** *************@n ews.skynet.be.. .
Yes you can make a function that will search your recordset and return the
id

Private function ReturnId(firstn ame as string,lastname as string) as long dim rst as adodb.recordset
set rst = new adodb.recordset
with rst
.open "select teacherid from tblteachers where firstname = '" &
firstname "' and lastname = '" & lastname & "'", db, adOpenDynamic,
adLockReadOnly
if not .eof and not .bof then
.movefirst
returnid = .fields("teache rid").value
else
returid = 0 'no teacherid found
end if
.close
end with
set rst = nothing

But this will return the entire database into the recordset, and I
understand it, and then put the userID into returnID. That is not very
scallable if the database is very large.

Adrian


John has the right approach.

The Recorset Query will only return the data requested - not the entire
database. More than likely the recordset will only contain 1 record
consisting of 1 field (*teacherID*). A Recordset is not the same as a
Database. A Recordset is a Table. The Query designates the amount and type
of data returned/referenced in that table.

Regards
Mike



end function

(PS function not tested)

Greets John

"Adrian Parker" <ad***********@ NOSPAMsympatico .ca> schreef in bericht
news:1Z******** ***********@new s20.bellglobal. com...

"John Lauwers" <no****@fictief .com> wrote in message
news:40******** *************@n ews.skynet.be.. .
> select teacherid from tblteachers where firstname = 'Jane' and

lastname
=
> 'Doe'

Thank you.

Can I do that without making a new RecordSet variable? Storing the

entire recordset just to return one integer seems wasteful.

Ideally I want something like this:

Dim driverID as integer
driverID = 'Query here which returns the driverID for one record from
database'
Adrian

> "Adrian Parker" <ad***********@ NOSPAMsympatico .ca> schreef in bericht > news:1Z******** ************@ne ws20.bellglobal .com...
> > Hi. I would like to query a database, given several where clauses to > refine
> > my search, and return the value of one single field in the database. > >
> > eg: I have a table that lists teachers. Their first name, last name, > age,
> > unique teacher number, etc is in the file.
> >
> > I want to return the unique teacher number, for example, of the

teacher
> > whose first name is Jane and last name is Doe.
> >
> > How does one do this?



Jul 17 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
34174
by: Clay Beatty | last post by:
When you create database diagrams in Enterprise Manager, the details for constructing those diagrams is saved into the dtproperties table. This table includes an image field which contains most of the relevant infomation, in a binary format. SQL Enterprise manager offers no way to script out those diagrams, so I have created two Transact SQL components, one User Function and one User Procedure, which together provide a means to script...
5
4041
by: George | last post by:
This program need to draw the some triangles into a 512 × 512 buffer (in memory). Or save it to a file. #include "project3.h" Image::Image(int xres, int yres): xres(xres), yres(yres) { image =new Color*; for (int i=0;i<yres;i++)
8
3125
by: MacDermott | last post by:
I have a query, which gathers up information, which is subsequently dumped into an instance of Excel using recordsetcopy. For one of the query fields, I have written what should be a pretty simple little function with three arguments, a switch (integer) and 2 date fields. For certain values of the switch, I use one date field, for others, the other date field, and for switch values which are neither, I need to return a blank. Well,...
3
1691
by: Felix Kater | last post by:
Hi, normally I use a local variable assigned to different return values inside the function and return it like this: int f(){ int my_err_code; my_err_code=1;
6
4849
by: jjturon | last post by:
Can anyone help me?? I am trying to pass a Select Query variable to a table using Dlookup and return the value to same select query but to another field. Ex. SalesManID SalesManName AT Alan Time
8
8053
by: Roland Hall | last post by:
In Access you use "*" + + "*", + can be replaced with & Calling a parameterized query in Access requires % be used in place of *, however, all that I have read show dynamic SQL passed to Access: WHERE LIKE '" & ASPvar & "' % ORDER BY ... However, my call is similar to: conn.qMyLookup strVar, rs
2
3197
by: Flic | last post by:
Hi, I have a basic db that I access with MySQL query browser. Everything seems fine to me but I am using this db as part of a php shopping basket and when I try to add an item I get: Notice: Query failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '>function.extract]: First argument should be an array in functions.inc.php on line 31
4
4587
by: zion4ever | last post by:
Hello good people, Please bear with me as this is my first post and I am relative new to ASP. I do have VB6 experience. I have a form which enables users within our company to do an intranet reservation of available resources (laptops, beamers, etc). The MySql database queries are already in place, as is the ASP administration panel. The frontend that users will see however, still needs some work. I'm really close, but since I'm no...
1
2281
by: kiranbabu | last post by:
<html> <head> <style type="text/css"> h2{color:#A02820} </style> </head> <script language=javascript>
0
9629
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9465
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10068
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9923
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8954
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7474
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5497
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3627
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2863
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.