Solved

SQL Statement (Union)

Posted on 2002-04-15
3
131 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
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

696 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