Solved

SQL Statement (Union)

Posted on 2002-04-15
3
132 Views
Last Modified: 2012-05-04
Hello,

VB6(sp5) ADO

I need to combine the following fields from two tables in an sql statement.

Table1: One_tbl
Field: Location_fld1

Table2: Two_tbl
Field: Location_fld2

I need to combine these fields when data is present only. If there is an empty string or the fields are NULL I don't want them in the sql recordset.

Thanks,

ADawn
0
Comment
Question by:ADawn
[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
 

Expert Comment

by:clangl
ID: 6943093
SELECT Location_fld1 FROM One_tbl
WHERE Location_fld1<>NULL and TRIM(Location_fld1)<> ""
UNION
SELECT Location_fld2 FROM Two_tbl
WHERE Location_fld2<>NULL and TRIM(Location_fld2<>) ""
0
 
LVL 18

Accepted Solution

by:
mdougan earned 10 total points
ID: 6943240
What do you mean by combine them.  If you mean concatenate them, then you'll need to tell us what field joins the two_tbl to the one_tbl

You will most likely need to use a Union as clangl is showing, but I'm not sure if you can do both the check for null and the trim in the same where clause.  Also, I'm not sure if <> Null is valid.  Normally, in ANSI Standard SQL you'd say

Where Location_fld2 is not null (access SQL could be different)

Alternately, you could check for a length greater than zero, which should eliminate all nulls and empty strings:

SELECT Location_fld2 FROM Two_tbl
WHERE Len(Trim(Location_fld2 & "")) > 0
0
 

Author Comment

by:ADawn
ID: 6947737
mdougan

For your example to work I had to add single quotes as follows.

SELECT Location_fld2 FROM Two_tbl
WHERE Len(Trim(Location_fld2 & '')) > 0

It works, Thanks.

ADawn
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

724 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