Solved

SQL Statement (Union)

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

707 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now