?
Solved

SQL Statement (Union)

Posted on 2002-04-15
3
Medium Priority
?
133 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 40 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
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…
Suggested Courses
Course of the Month14 days, 7 hours left to enroll

770 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