Solved

Combine Two Datasets

Posted on 2014-12-10
3
94 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
[X]
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
3 Comments
 
LVL 50

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:Huseyin KAHRAMAN
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

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

749 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