A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Using LookUp tables in sql query,need help



 
 
Thread Tools Display Modes
  #1  
Old August 31st, 2004, 08:55 AM
Julia
external usenet poster
 
Posts: n/a
Default Using LookUp tables in sql query,need help

Hi,

I need help with the following query,
I have two LookUp tables:

Cities

Id Name
1 USA
2 UK

Courtiers

Id Name
1 Boston
2 London


assuming user input City and Country NAME,I need to get the ID for the names
if possible in one query(I know of course how to do it in several queries)
if the query cannot find a name it should return -1

for example

User Input:

City:LANDON(note for the 'A')
Country:USA

excepted output:
-1,1


Thanks in advance.



  #2  
Old August 31st, 2004, 12:33 PM
Michel Walsh
external usenet poster
 
Posts: n/a
Default

Hi,




SELECT Nz(DLookup("id" , "Courtiers", "Name=City" ), -1),
Nz(DLookup("id", "Cities", "Name=Country" ), - 1)





no FROM clause.




Hoping it may help,
Vanderghast, Access MVP


"Julia" wrote in message
...
Hi,

I need help with the following query,
I have two LookUp tables:

Cities

Id Name
1 USA
2 UK

Courtiers

Id Name
1 Boston
2 London


assuming user input City and Country NAME,I need to get the ID for the
names
if possible in one query(I know of course how to do it in several queries)
if the query cannot find a name it should return -1

for example

User Input:

City:LANDON(note for the 'A')
Country:USA

excepted output:
-1,1


Thanks in advance.





  #3  
Old August 31st, 2004, 03:02 PM
Julia
external usenet poster
 
Posts: n/a
Default

Thanks.

"Michel Walsh" vanderghast@VirusAreFunnierThanSpam wrote in message
...
Hi,




SELECT Nz(DLookup("id" , "Courtiers", "Name=City" ), -1),
Nz(DLookup("id", "Cities", "Name=Country" ), - 1)





no FROM clause.




Hoping it may help,
Vanderghast, Access MVP


"Julia" wrote in message
...
Hi,

I need help with the following query,
I have two LookUp tables:

Cities

Id Name
1 USA
2 UK

Courtiers

Id Name
1 Boston
2 London


assuming user input City and Country NAME,I need to get the ID for the
names
if possible in one query(I know of course how to do it in several

queries)
if the query cannot find a name it should return -1

for example

User Input:

City:LANDON(note for the 'A')
Country:USA

excepted output:
-1,1


Thanks in advance.







  #4  
Old August 31st, 2004, 03:55 PM
JG316
external usenet poster
 
Posts: n/a
Default

Would this same method work within a Query?

Expr1: DLookUp("[County_Name]","Q02 County","[County_Code]
=County")

County is one of the fields I choose in the query, but I
get the error "Can't find the name County you used in the
expression". If I hard code a value for County, it does a
static lookup, but I want to base it on the County value
selected in the query.

-----Original Message-----
Hi,




SELECT Nz(DLookup("id" , "Courtiers", "Name=City" ), -1),
Nz(DLookup("id", "Cities", "Name=Country" ), - 1)





no FROM clause.




Hoping it may help,
Vanderghast, Access MVP


"Julia" wrote in message
...
Hi,

I need help with the following query,
I have two LookUp tables:

Cities

Id Name
1 USA
2 UK

Courtiers

Id Name
1 Boston
2 London


assuming user input City and Country NAME,I need to get

the ID for the
names
if possible in one query(I know of course how to do it

in several queries)
if the query cannot find a name it should return -1

for example

User Input:

City:LANDON(note for the 'A')
Country:USA

excepted output:
-1,1


Thanks in advance.





.

  #5  
Old August 31st, 2004, 05:43 PM
Michel Walsh
external usenet poster
 
Posts: n/a
Default

Hi,


Should try:

Expr1: DLookUp("[County_Name]","Q02 County", "[County_Code]=" & County )


The third argument has to be coputed before being send to DLookup, so, the
actual value hold in County is then "imprinted" by the concatenation, and
DLookup sees something like ""[County_Code]=1023" .



Hoping it may help,
Vanderghast, Access MVP


"JG316" wrote in message
...
Would this same method work within a Query?

Expr1: DLookUp("[County_Name]","Q02 County","[County_Code]
=County")

County is one of the fields I choose in the query, but I
get the error "Can't find the name County you used in the
expression". If I hard code a value for County, it does a
static lookup, but I want to base it on the County value
selected in the query.

-----Original Message-----
Hi,




SELECT Nz(DLookup("id" , "Courtiers", "Name=City" ), -1),
Nz(DLookup("id", "Cities", "Name=Country" ), - 1)





no FROM clause.




Hoping it may help,
Vanderghast, Access MVP


"Julia" wrote in message
...
Hi,

I need help with the following query,
I have two LookUp tables:

Cities

Id Name
1 USA
2 UK

Courtiers

Id Name
1 Boston
2 London


assuming user input City and Country NAME,I need to get

the ID for the
names
if possible in one query(I know of course how to do it

in several queries)
if the query cannot find a name it should return -1

for example

User Input:

City:LANDON(note for the 'A')
Country:USA

excepted output:
-1,1


Thanks in advance.





.



  #6  
Old August 31st, 2004, 06:13 PM
JG316
external usenet poster
 
Posts: n/a
Default

Tried that ... getting the error 'Data type mismatch in
criteria expression'. County_Code and County are text
fields. I tried hardcoding a value in for County, but get
the same error.


-----Original Message-----
Hi,


Should try:

Expr1: DLookUp("[County_Name]","Q02

County", "[County_Code]=" & County )


The third argument has to be coputed before being send to

DLookup, so, the
actual value hold in County is then "imprinted" by the

concatenation, and
DLookup sees something like ""[County_Code]=1023" .



Hoping it may help,
Vanderghast, Access MVP


"JG316" wrote in

message
...
Would this same method work within a Query?

Expr1: DLookUp("[County_Name]","Q02

County","[County_Code]
=County")

County is one of the fields I choose in the query, but I
get the error "Can't find the name County you used in

the
expression". If I hard code a value for County, it

does a
static lookup, but I want to base it on the County value
selected in the query.

-----Original Message-----
Hi,




SELECT Nz(DLookup("id" , "Courtiers", "Name=City" ), -

1),
Nz(DLookup("id", "Cities", "Name=Country" ), - 1)





no FROM clause.




Hoping it may help,
Vanderghast, Access MVP


"Julia" wrote in message
...
Hi,

I need help with the following query,
I have two LookUp tables:

Cities

Id Name
1 USA
2 UK

Courtiers

Id Name
1 Boston
2 London


assuming user input City and Country NAME,I need to

get
the ID for the
names
if possible in one query(I know of course how to do it

in several queries)
if the query cannot find a name it should return -1

for example

User Input:

City:LANDON(note for the 'A')
Country:USA

excepted output:
-1,1


Thanks in advance.





.



.

  #7  
Old August 31st, 2004, 06:33 PM
Michel Walsh
external usenet poster
 
Posts: n/a
Default

Hi,

If they are text, then:


Expr1: DLookUp("[County_Name]","Q02 County", "[County_Code]=""" & County &
"""" )



Hoping it may help,
Vanderghast, Access MVP


"JG316" wrote in message
...
Tried that ... getting the error 'Data type mismatch in
criteria expression'. County_Code and County are text
fields. I tried hardcoding a value in for County, but get
the same error.


-----Original Message-----
Hi,


Should try:

Expr1: DLookUp("[County_Name]","Q02

County", "[County_Code]=" & County )


The third argument has to be coputed before being send to

DLookup, so, the
actual value hold in County is then "imprinted" by the

concatenation, and
DLookup sees something like ""[County_Code]=1023" .



Hoping it may help,
Vanderghast, Access MVP


"JG316" wrote in

message
...
Would this same method work within a Query?

Expr1: DLookUp("[County_Name]","Q02

County","[County_Code]
=County")

County is one of the fields I choose in the query, but I
get the error "Can't find the name County you used in

the
expression". If I hard code a value for County, it

does a
static lookup, but I want to base it on the County value
selected in the query.

-----Original Message-----
Hi,




SELECT Nz(DLookup("id" , "Courtiers", "Name=City" ), -

1),
Nz(DLookup("id", "Cities", "Name=Country" ), - 1)





no FROM clause.




Hoping it may help,
Vanderghast, Access MVP


"Julia" wrote in message
.. .
Hi,

I need help with the following query,
I have two LookUp tables:

Cities

Id Name
1 USA
2 UK

Courtiers

Id Name
1 Boston
2 London


assuming user input City and Country NAME,I need to

get
the ID for the
names
if possible in one query(I know of course how to do it
in several queries)
if the query cannot find a name it should return -1

for example

User Input:

City:LANDON(note for the 'A')
Country:USA

excepted output:
-1,1


Thanks in advance.





.



.



  #8  
Old August 31st, 2004, 07:32 PM
JG316
external usenet poster
 
Posts: n/a
Default

Most helpful, thanks

-----Original Message-----
Hi,

If they are text, then:


Expr1: DLookUp("[County_Name]","Q02

County", "[County_Code]=""" & County &
"""" )



Hoping it may help,
Vanderghast, Access MVP


"JG316" wrote in message
...
Tried that ... getting the error 'Data type mismatch in
criteria expression'. County_Code and County are text
fields. I tried hardcoding a value in for County, but

get
the same error.


-----Original Message-----
Hi,


Should try:

Expr1: DLookUp("[County_Name]","Q02

County", "[County_Code]=" & County )


The third argument has to be coputed before being send

to
DLookup, so, the
actual value hold in County is then "imprinted" by the

concatenation, and
DLookup sees something like ""[County_Code]=1023" .



Hoping it may help,
Vanderghast, Access MVP


"JG316" wrote in

message
.. .
Would this same method work within a Query?

Expr1: DLookUp("[County_Name]","Q02

County","[County_Code]
=County")

County is one of the fields I choose in the query,

but I
get the error "Can't find the name County you used in

the
expression". If I hard code a value for County, it

does a
static lookup, but I want to base it on the County

value
selected in the query.

-----Original Message-----
Hi,




SELECT Nz(DLookup

("id" , "Courtiers", "Name=City" ), -
1),
Nz(DLookup("id", "Cities", "Name=Country" ), - 1)





no FROM clause.




Hoping it may help,
Vanderghast, Access MVP


"Julia" wrote in message
. ..
Hi,

I need help with the following query,
I have two LookUp tables:

Cities

Id Name
1 USA
2 UK

Courtiers

Id Name
1 Boston
2 London


assuming user input City and Country NAME,I need to

get
the ID for the
names
if possible in one query(I know of course how to do

it
in several queries)
if the query cannot find a name it should return -1

for example

User Input:

City:LANDON(note for the 'A')
Country:USA

excepted output:
-1,1


Thanks in advance.





.



.



.

 




Thread Tools
Display Modes

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 Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Function isn't available in expressions in query expression Reiner Harmgardt General Discussion 4 July 21st, 2004 09:30 AM
Lookup fields - what's wrong with them? NATHAN SANDERS New Users 2 May 4th, 2004 10:51 AM


All times are GMT +1. The time now is 10:59 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.