View Full Version : Get Rowscource in Select Query


icthi75
07-30-2008, 06:15 AM
I am trying to do a simple SELECT query from vb.net

SELECT * from tblEmpTime

However, the column [TCID] is a combobox linked to tblTC.

The first query result for this column is "15 Permitting" where "15" comes from the tblTC.TaskCode and the "Permitting" comes from tblTC.Desc

Is there a command i can put in the query to just show the tblTC.TaskCode part? I dont want to change the database itself just the query if possible.

Thanks

Banana
07-30-2008, 06:25 AM
If you don't want to display all columns, then don't use "SELECT *" which does just that.

You would want something like "SELECT TaskCode FROM tblEmpTime;".

I'm confused by this sentence:

However, the column [TCID] is a combobox linked to tblTC.

Queries has no comboboxes, and I'm not sure whether you are thinking of forms in Access or a lookup field.

icthi75
07-30-2008, 06:33 AM
I do want all columns

but the TCID column is somehow derived from 2 columns in another table of which i only want to see one

if i open the tblEmpTime table in Design view the look up row source is set to a string combine of tblTC.TCID and tblTC.Desc

Banana
07-30-2008, 06:38 AM
So you're using lookup fields? Evils of Lookup fields. (http://mvps.org/access/lookupfields.htm)

icthi75
07-30-2008, 06:41 AM
i did not set up this database nor can i alter it for now.

is there a way to get the info i need despite someone else's poor setup?

Banana
07-30-2008, 06:54 AM
if the code doesn't have any spaces, and it's always a space in between, you could only read the left part of string prior to the space. Something like this (you may need to check for builtin functions supported by Jet ODBC or OLE DB provider):

Example:
SELECT LEFT(TCIDCode, LOCATE(" ", TCIDCode)) FROM tmpEmp

Read the documentation to get the correct functions and arguments for each.