Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Queries / August 2006

Tip: Looking for answers? Try searching our database.

Need help With Inner Join Select Statement

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Justin - 07 Aug 2006 23:13 GMT
I'm accessing an MSAccess DB from within VB.NET.  To start here is my OLD
select statement which works 100% and has provided the data I need for many
years:

SELECT TimeSheets.Employee, TimeSheets.[Hol Hours], TimeSheets.[Job Date],
TimeSheets.[Job Number], TimeSheets.[Over Hours], TimeSheets.[Period Start],
Employee.Employee AS Expr1, Employee.Type, TimeSheets.Dept, TimeSheets.GL
FROM (Employee INNER JOIN TimeSheets ON Employee.Employee =
TimeSheets.Employee) WHERE [Period Start] = @PeriodStart AND [Over Hours] >
0

You will notice I pull from TimeSheets and Employee.  What I'm trying to do
now is add a third table "Jobs" to pull one more field into my report.  Here
is my attempt:

SELECT TimeSheets.Employee, TimeSheets.[Hol Hours], TimeSheets.[Job Date],
TimeSheets.[Job Number], TimeSheets.[Over Hours], TimeSheets.[Period Start],
Employee.Employee AS Expr1, Employee.Type, TimeSheets.Dept, TimeSheets.GL,
Jobs.[Job Number], Jobs.[Job Name] FROM (Employee INNER JOIN TimeSheets ON
Employee.Employee = TimeSheets.Employee) INNER JOIN Jobs ON TimeSheets.[Job
Number] = Jobs.[Job Number] WHERE [Period Start] = @PeriodStart AND [Over
Hours] > 0

This results in an empty dataset.  Nothing is selected form the DB.  If I
remove the WHERE statement I get a very odd and very small dataset of
mismatched data.  When I use the original select statement I get over 3,000
results.  I'm expecting the exact same amount of result with the new select
statement only with a new field added (the name of the job).

I would appreciate any help on this matter and thanks in advance!!!
Justin - 07 Aug 2006 23:56 GMT
Doh!  Slight change.  I  just noticed that the table Jobs was empty.  Thus
it had nothing to select.  Someone dropped the ball I guess.

I just added as much of the job numbers as I needed for my current report
and I am now filling my dataset.  I haven't tried to get that new field yet
but at least I'm back up to speed.

I had to make one change.  I had to remove Jobs.[Job Number].  I guess since
I was already pulling that field from TimeSheets?? It wasn't pulling that
field at all until I removed the duplicate.  However my dataset, from what I
can tell, doesn't unclude the new field.  The temp DataGrid I'm using should
populate it right?

I'm going to mess with this for a little bit and see what happens.
Justin - 08 Aug 2006 00:14 GMT
Ok, so now I'm back to getting my data however that second INNER JOIN isn't
working.  I'm not getting any data from my third table JOBS.

SELECT TimeSheets.Employee, TimeSheets.[Hol Hours], TimeSheets.[Job Date],
TimeSheets.[Job Number], TimeSheets.[Over Hours], TimeSheets.[Period Start],
Employee.Employee AS Expr1, Employee.Type, TimeSheets.Dept, TimeSheets.GL,
Jobs.[Job Name] FROM (Employee INNER JOIN TimeSheets ON Employee.Employee =
TimeSheets.Employee) INNER JOIN Jobs ON TimeSheets.[Job Number] = Jobs.[Job
Number] WHERE [Period Start] = @PeriodStart AND [Over Hours] > 0

So ultimately, I'm not getting Jobs.[Job Name]

Again I would greatly appreciate any help on this mater.
Justin - 08 Aug 2006 01:44 GMT
When I use that SQL Statement in Access I get all the data I need.  So I'm
not sure why VB.NET refused to see that new field.  If I try to select
columns on the datagrid it wont bring up the new field at all.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.