Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Combine Two Datasets

Posted on 2014-12-10
3
92 Views
Last Modified: 2015-01-19
Dear all,

I'm trying to combine two datasets, tables LocationData and MonitoredData based on matching values in field2 and field3.  All field types are string.  Sorry for the names I decided to make it simple to explain it.

Does the below query look like it will work?  Its not returning any results.

SELECT [LocationData].Field1, [LocationData].Field4, MonitoredData.Field2, MonitoredData.Field3 INTO MappingTable
FROM [LocationData] INNER JOIN MonitoredData ON [LocationData].Field3= MonitoredData.Field3
WHERE ((([LocationData].Field1) Is Not Null) AND ((MonitoredData.Field2)=[LocationData].Field2) AND ((MonitoredData.Field3)=[LocationData].Field3));

Open in new window


Thanks
0
Comment
Question by:AndyC1000
3 Comments
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 40493274
It could be reduced to:

SELECT
    [LocationData].Field1,
    [LocationData].Field4,
    MonitoredData.Field2,
    MonitoredData.Field3
INTO
    MappingTable
FROM
    [LocationData],
    MonitoredData
WHERE
    [LocationData].Field1 Is Not Null
    AND
    MonitoredData.Field2 = [LocationData].Field2
    AND
    MonitoredData.Field3 = [LocationData].Field3;

/gustav
0
 
LVL 51

Expert Comment

by:HainKurt
ID: 40494080
Its not returning any results.

of course it will not... it is inserting into some table...

remove into statement...

SELECT l.Field1, l.Field4, m.Field2, m.Field3
FROM [LocationData] l 
INNER JOIN MonitoredData m ON l.Field3= m.Field3 AND m.Field2=l.Field2 AND l.Field1 Is Not Null

Open in new window

0
 
LVL 36

Accepted Solution

by:
PatHartman earned 500 total points
ID: 40494096
I would change the join to include both fields.

SELECT [LocationData].Field1, [LocationData].Field4, MonitoredData.Field2, MonitoredData.Field3 INTO MappingTable
FROM [LocationData] INNER JOIN MonitoredData ON [LocationData].Field3 = MonitoredData.Field3 AND MonitoredData.Field2 =[LocationData].Field2
WHERE [LocationData].Field1 Is Not Null;

But the suggested change is for efficiency.  It shouldn't change the result.  If the query is not returning any rows, it is because there are none that match.

To debug, I would back out one condition at a time.  So start by removing the where clause.  If that doesn't work, remove the second field in the join.  If that doesn't work, put the second field back and remove the first.

You should also examine the data.  It is possible that one table has trailing blanks or something in the columns and that will prevent the join from working.
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question