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. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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 | |
|
|
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 |