Hello,
I am an excel user and new to access. I would like to use the dlookup function in an SQL query.
I have created a simple database made up of two tables, lookup_tbl and Data_tbl, to write a practice SQL code using DLookup.
My lookup_tbl is a two column table shown below:
<table bgcolor="#ffffff" border="1" cellspacing="0"><caption>Lookup_tbl</caption> <thead> <tr> <th bordercolor="#000000" bgcolor="#c0c0c0">lookup_value</th> <th bordercolor="#000000" bgcolor="#c0c0c0">return_value</th> </tr> </thead> <tbody> <tr valign="TOP"> <td bordercolor="#c0c0c0">lookup_1</td> <td bordercolor="#c0c0c0">return_1</td> </tr> <tr valign="TOP"> <td bordercolor="#c0c0c0">lookup_2</td> <td bordercolor="#c0c0c0">return_2</td> </tr> <tr valign="TOP"> <td bordercolor="#c0c0c0">lookup_3</td> <td bordercolor="#c0c0c0">return_3</td> </tr> </tbody> <tfoot></tfoot> </table>
My Data_tbl is shown below:
<table bgcolor="#ffffff" border="1" cellspacing="0"><caption>Data_tbl</caption> <thead> <tr> <th bordercolor="#000000" bgcolor="#c0c0c0">col_A</th> </tr> </thead> <tbody> <tr valign="TOP"> <td bordercolor="#c0c0c0">lookup_1</td> </tr> <tr valign="TOP"> <td bordercolor="#c0c0c0">lookup_2</td> </tr> <tr valign="TOP"> <td bordercolor="#c0c0c0">lookup_1</td> </tr> <tr valign="TOP"> <td bordercolor="#c0c0c0">lookup_3</td> </tr> <tr valign="TOP"> <td bordercolor="#c0c0c0">lookup_1</td> </tr> <tr valign="TOP"> <td bordercolor="#c0c0c0">lookup_1</td> </tr> <tr valign="TOP"> <td bordercolor="#c0c0c0">lookup_3</td> </tr> </tbody> <tfoot></tfoot> </table>
I would like to write a query in SQL that creates a new table which matches the values of Data_tbl using lookup_tbl and returning the corresponding values in lookup_tbl.
In other words I would like to end up with this:
<table bgcolor="#ffffff" border="1" cellspacing="0"><caption>Data_tbl</caption> <thead> <tr> <th bordercolor="#000000" bgcolor="#c0c0c0">col_A</th> <th bordercolor="#000000" bgcolor="#c0c0c0">col_B</th> </tr> </thead> <tbody> <tr valign="TOP"> <td bordercolor="#c0c0c0">lookup_1</td> <td bordercolor="#c0c0c0">return_1</td> </tr> <tr valign="TOP"> <td bordercolor="#c0c0c0">lookup_2</td> <td bordercolor="#c0c0c0">return_2</td> </tr> <tr valign="TOP"> <td bordercolor="#c0c0c0">lookup_1</td> <td bordercolor="#c0c0c0">return_1</td> </tr> <tr valign="TOP"> <td bordercolor="#c0c0c0">lookup_3</td> <td bordercolor="#c0c0c0">return_3</td> </tr> <tr valign="TOP"> <td bordercolor="#c0c0c0">lookup_1</td> <td bordercolor="#c0c0c0">return_1</td> </tr> <tr valign="TOP"> <td bordercolor="#c0c0c0">lookup_1</td> <td bordercolor="#c0c0c0">return_1</td> </tr> <tr valign="TOP"> <td bordercolor="#c0c0c0">lookup_3</td> <td bordercolor="#c0c0c0">return_3</td> </tr> </tbody> <tfoot></tfoot> </table>
So I created a query, lookup_test, and placed the following code in it.
SELECT Data_tbl.col_A, DLookUp("[return_value]","Lookup_tbl") AS col_B
FROM Data_tbl;
However, when I run this query I end up with this:
<table bgcolor="#ffffff" border="1" cellspacing="0"><caption>lookup_test</caption> <thead> <tr> <th bordercolor="#000000" bgcolor="#c0c0c0">col_A</th> <th bordercolor="#000000" bgcolor="#c0c0c0">col_B</th> </tr> </thead> <tbody> <tr valign="TOP"> <td bordercolor="#c0c0c0">lookup_1</td> <td bordercolor="#c0c0c0">return_1</td> </tr> <tr valign="TOP"> <td bordercolor="#c0c0c0">lookup_2</td> <td bordercolor="#c0c0c0">return_1</td> </tr> <tr valign="TOP"> <td bordercolor="#c0c0c0">lookup_1</td> <td bordercolor="#c0c0c0">return_1</td> </tr> <tr valign="TOP"> <td bordercolor="#c0c0c0">lookup_3</td> <td bordercolor="#c0c0c0">return_1</td> </tr> <tr valign="TOP"> <td bordercolor="#c0c0c0">lookup_1</td> <td bordercolor="#c0c0c0">return_1</td> </tr> <tr valign="TOP"> <td bordercolor="#c0c0c0">lookup_1</td> <td bordercolor="#c0c0c0">return_1</td> </tr> <tr valign="TOP"> <td bordercolor="#c0c0c0">lookup_3</td> <td bordercolor="#c0c0c0">return_1</td> </tr> </tbody> <tfoot></tfoot> </table>
I know that this is a rookie level question but I can not figure out the syntax for Dlookup. As you can see above it just looked up the first value and returned it for all of the values. Does anyone know the correct syntax?
Thanks in advance
Moradwan
I am an excel user and new to access. I would like to use the dlookup function in an SQL query.
I have created a simple database made up of two tables, lookup_tbl and Data_tbl, to write a practice SQL code using DLookup.
My lookup_tbl is a two column table shown below:
<table bgcolor="#ffffff" border="1" cellspacing="0"><caption>Lookup_tbl</caption> <thead> <tr> <th bordercolor="#000000" bgcolor="#c0c0c0">lookup_value</th> <th bordercolor="#000000" bgcolor="#c0c0c0">return_value</th> </tr> </thead> <tbody> <tr valign="TOP"> <td bordercolor="#c0c0c0">lookup_1</td> <td bordercolor="#c0c0c0">return_1</td> </tr> <tr valign="TOP"> <td bordercolor="#c0c0c0">lookup_2</td> <td bordercolor="#c0c0c0">return_2</td> </tr> <tr valign="TOP"> <td bordercolor="#c0c0c0">lookup_3</td> <td bordercolor="#c0c0c0">return_3</td> </tr> </tbody> <tfoot></tfoot> </table>
My Data_tbl is shown below:
<table bgcolor="#ffffff" border="1" cellspacing="0"><caption>Data_tbl</caption> <thead> <tr> <th bordercolor="#000000" bgcolor="#c0c0c0">col_A</th> </tr> </thead> <tbody> <tr valign="TOP"> <td bordercolor="#c0c0c0">lookup_1</td> </tr> <tr valign="TOP"> <td bordercolor="#c0c0c0">lookup_2</td> </tr> <tr valign="TOP"> <td bordercolor="#c0c0c0">lookup_1</td> </tr> <tr valign="TOP"> <td bordercolor="#c0c0c0">lookup_3</td> </tr> <tr valign="TOP"> <td bordercolor="#c0c0c0">lookup_1</td> </tr> <tr valign="TOP"> <td bordercolor="#c0c0c0">lookup_1</td> </tr> <tr valign="TOP"> <td bordercolor="#c0c0c0">lookup_3</td> </tr> </tbody> <tfoot></tfoot> </table>
I would like to write a query in SQL that creates a new table which matches the values of Data_tbl using lookup_tbl and returning the corresponding values in lookup_tbl.
In other words I would like to end up with this:
<table bgcolor="#ffffff" border="1" cellspacing="0"><caption>Data_tbl</caption> <thead> <tr> <th bordercolor="#000000" bgcolor="#c0c0c0">col_A</th> <th bordercolor="#000000" bgcolor="#c0c0c0">col_B</th> </tr> </thead> <tbody> <tr valign="TOP"> <td bordercolor="#c0c0c0">lookup_1</td> <td bordercolor="#c0c0c0">return_1</td> </tr> <tr valign="TOP"> <td bordercolor="#c0c0c0">lookup_2</td> <td bordercolor="#c0c0c0">return_2</td> </tr> <tr valign="TOP"> <td bordercolor="#c0c0c0">lookup_1</td> <td bordercolor="#c0c0c0">return_1</td> </tr> <tr valign="TOP"> <td bordercolor="#c0c0c0">lookup_3</td> <td bordercolor="#c0c0c0">return_3</td> </tr> <tr valign="TOP"> <td bordercolor="#c0c0c0">lookup_1</td> <td bordercolor="#c0c0c0">return_1</td> </tr> <tr valign="TOP"> <td bordercolor="#c0c0c0">lookup_1</td> <td bordercolor="#c0c0c0">return_1</td> </tr> <tr valign="TOP"> <td bordercolor="#c0c0c0">lookup_3</td> <td bordercolor="#c0c0c0">return_3</td> </tr> </tbody> <tfoot></tfoot> </table>
So I created a query, lookup_test, and placed the following code in it.
SELECT Data_tbl.col_A, DLookUp("[return_value]","Lookup_tbl") AS col_B
FROM Data_tbl;
However, when I run this query I end up with this:
<table bgcolor="#ffffff" border="1" cellspacing="0"><caption>lookup_test</caption> <thead> <tr> <th bordercolor="#000000" bgcolor="#c0c0c0">col_A</th> <th bordercolor="#000000" bgcolor="#c0c0c0">col_B</th> </tr> </thead> <tbody> <tr valign="TOP"> <td bordercolor="#c0c0c0">lookup_1</td> <td bordercolor="#c0c0c0">return_1</td> </tr> <tr valign="TOP"> <td bordercolor="#c0c0c0">lookup_2</td> <td bordercolor="#c0c0c0">return_1</td> </tr> <tr valign="TOP"> <td bordercolor="#c0c0c0">lookup_1</td> <td bordercolor="#c0c0c0">return_1</td> </tr> <tr valign="TOP"> <td bordercolor="#c0c0c0">lookup_3</td> <td bordercolor="#c0c0c0">return_1</td> </tr> <tr valign="TOP"> <td bordercolor="#c0c0c0">lookup_1</td> <td bordercolor="#c0c0c0">return_1</td> </tr> <tr valign="TOP"> <td bordercolor="#c0c0c0">lookup_1</td> <td bordercolor="#c0c0c0">return_1</td> </tr> <tr valign="TOP"> <td bordercolor="#c0c0c0">lookup_3</td> <td bordercolor="#c0c0c0">return_1</td> </tr> </tbody> <tfoot></tfoot> </table>
I know that this is a rookie level question but I can not figure out the syntax for Dlookup. As you can see above it just looked up the first value and returned it for all of the values. Does anyone know the correct syntax?
Thanks in advance
Moradwan