?
Solved

SQL Statement (Union)

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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

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