Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help with using "if" in the sql statement

Status
Not open for further replies.

jpack23

Programmer
Dec 15, 2004
82
US
thanks for taking a look at this. I would like to know if the following can be done in a sql statement.

I have 2 tables that goes something like this:

TABLE1
FieldID integer
FieldDeptID integer
FieldName varchar
FieldAbbrev varchar

TABLE2
fieldDeptID
fieldDeptName


The data in this table looks like this:

Table1

fieldID FieldDeptID FieldName FieldAbbrev

1 1 Labor SNL
2 2 Labor ANL

Table2

FieldDeptID fieldName
1 accounting
2 IT


I would like to write a sql statement that looks at the fieldDeptID and then combines the fieldname from table1 with the deptname from table2

I am using this statement to populate a dropdown combox box in a VB form and in the Display member I want to see the field name with the department name for example. Since there is two "Labor" names I want the combo box to show the user which department the "labor" name belongs to.

ex: Labor Accounting
Labor IT

I hope I explained this right. Can this be done in a sql statement or do I need to do this in VB 2008 code(which i dont know how to do either) Any help would be great

thanks
Joe
 
Code:
Select D.FieldName + space(1) + F.FieldName as FullName from Table1 F inner join Table2 D on F.FieldDeptID = D.FieldDeptID

Try researching on the INNER JOIN syntax and you may want to read about different kind of JOINs.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top