473,792 Members | 2,796 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Select distinct e-mail adress from 2 columns

2 New Member
Hello all,

I have a table (tblExport03) with the following fields:

ID : autonumber
Title : text
FirstName : text
LastName : text
OrganisationNam e : text
BusinessEmailAd dres : text (isNull, @ or valid e-mail address)
PrivateEmailAdd ress: text (isNull, @ or valid e-mail address)
NoMassMailing : checkbox (-1 = on = don't want to receive e-mail)

Some test data (abbreviated the column names)
ID FirstName LastName BusinessEmail PrivateEmail NoMass..
1 Bob Bobson bob#bob.com bob#priv.com 0
2 Jim Last last#jim.com jim#mail.com -1
3 Marc Johnson info#compy.com info#compy.com 0
4 Nicole Someone # info#compy.com 0
5 Hans Others hans#others.com 0
6 Tanja Big # # 0

(# = the 'at' sign)

My problem is that there are 2 columns with e-mail addresses that need to be combined into one column and then only select unique e-mail addresses.

So I get these records
ID FirstName LastName EmailAddress
1 Bob Bobson bob#bob.com
3 Marc Johnson info#compy.com
5 Hans Others hans#others.com

Both ID 3 and 4 have the same e-mail address, and for that matter I
don't care which one is selected.

There are some more restraints:
- if NoMassMailing = 0 then don't select person
- use only valid e-mail addresses (so filter out the empty and '@' values)
- if person has both Business and Private e-mail address only use the
Business e-mail address
- if person has only one e-mail address (Business OR Private) use this
address

Thanks already,
Niels
Oct 8 '06 #1
4 3265
PEB
1,418 Recognized Expert Top Contributor
Hi,

To combine your fields you need the function IIF()

An exemple like:

MyNewColumn: IIF(Isnull([Mail1]),[Mail2],[Mail1])

And you'll obtain all mails in 1 column with priority of Mail1

It's up to you to fit those things in your query!

:)
Oct 8 '06 #2
PEB
1,418 Recognized Expert Top Contributor
IIF has the following Structure:

IIF(Condition, When condition is true, When Condition is False)

:)
Oct 8 '06 #3
NielsM
2 New Member
Hi PEB,

Thanks for your reply and explanation.

At the moment I have my constraints figured out and get all e-mail addresses in one column. Problem is the e-mail addresses aren't unique.

This is what I have now:
SELECT tblExport03.ID, tblExport03.Fir stName, tblExport03.Las tName,

IIf([BusinessEmailAd dress] Is Null Or [BusinessEmailAd dress]="@",
IIf([PrivateEmailAdd ress] Is Null Or [PrivateEmailAdd ress]="@",Null,[PrivateEmailAdd ress]),[BusinessEmailAd dress]) AS EmailAddress

FROM tblExport03

WHERE (((IIf([BusinessEmailAd dress] Is Null Or [BusinessEmailAd dress]="@",

IIf([PrivateEmailAdd ress] Is Null Or [PrivateEmailAdd ress]="@",Null,[PrivateEmailAdd ress]),[BusinessEmailAd dress])) Is Not Null)
And ((tblExport03.N oMassMailing)=0 ))


Giving me these records
ID FirstName LastName EmailAddress
1 Bob Bobson bob#bob.com
3 Marc Johnson info#compy.com
4 Nicole Someone # info#compy.com
5 Hans Others hans#others.com

Records with ID 3 and 4 share have the same e-mail address... how do I select only one of these? Can I put a DISTINCT in an IIF Condition ?

Thanks,
Niels
Oct 8 '06 #4
PEB
1,418 Recognized Expert Top Contributor
Hi Niels,

You can group By / Distinct only on the column with IIF The other columns don't need to participate in your query. Is this idea is good for your task?

Best regards

Vladimir
Oct 14 '06 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

5
11692
by: Martin Feuersteiner | last post by:
Dear Group I'm having trouble with the clause below. I would like to select only records with a distinct TransactionDate but somehow it still lists duplicates. I need to select the TransactionDate once as smalldatetime and once as varchar as I'm populating a drop-down with Text/Value pairs. So I can't just use 'SELECT DISTINCT TransactionDate FROM...' I'm grateful for any hints.
3
10561
by: blue | last post by:
I'm trying to order a varchar column first numerically, and second alphanumerically using the following SQL: SELECT distinct doc_number FROM doc_line WHERE product_id = 'WD' AND doc_type = 'O' ORDER BY CASE WHEN IsNumeric(doc_number) = 1 THEN CONVERT(FLOAT, doc_number) ELSE 999999999 END,
3
2915
by: Cindy | last post by:
OK, I have the following table: create table citations_by_level ( aid smallint, wid smallint, v_level varchar(50), w_level varchar(50), x_level varchar(50), y_level varchar(50),
3
6472
by: Tcs | last post by:
My backend is DB2 on our AS/400. While I do HAVE DB2 PE for my PC, I haven't loaded it yet. I'm still using MS Access. And no, I don't believe this is an Access question. (But who knows? I COULD be wrong... :) I've tried the access group...twice...and all I get is "Access doesn't like ".", which I know, or that my query names are too long, as there's a limit to the length of the SQL statement(s). But this works when I don't try to...
9
10912
by: Kelvin | last post by:
Okay so this is baking my noodle. I want to select all the attritbutes/fields from a table but then to excluded any row in which a single attributes data has been duplicated. I.E. Here's my table:- ID Ref Name DATE 1 AAA Joe 1/2 2 BBB Ken 1/2 3 AAA Len 6/3
6
5560
by: John M | last post by:
Hi, The line below is used to feed a combobox. (It is from a database which is used to log pupil behaviour!) The 'incidents' table contains a list of students who have been involved in incidents. Some may appear several times, hence the Distinct. However, thelist generated should still be sorted by Surname. When I add Order by I'm told it conflict with the 'Distinct'. Surely it does not? SELECT DISTINCT ., . & " " & . FROM...
18
3067
by: mathilda | last post by:
My boss has been adamant that SELECT DISTINCT is a faster query than SELECT all other factors being equal. I disagree. We are linking an Access front end to a SQL Server back end and normally are only returning one record. She states that with disctinct the query stops as soon as it finds a matching record. Both of us are relative novices in database theory (obviously). Can someone help settle this?
3
5657
by: orekinbck | last post by:
Hi There Our test database has duplicate data: COMPANYID COMPANYNAME 1 Grupple Group 2 Grupple Group 5 Grupple Group 3 Yada Inc 4 Yada Inc
5
6899
by: Daniel Wetzler | last post by:
Dear MSSQL experts, I use MSSQL 2000 and encountered a strange problem wqhile I tried to use a select into statement . If I perform the command command below I get only one dataset which has the described properties. If I use the same statement in a select into statement (see the second select) I get several datasets with the described properties like I didn't use distinct
5
6444
by: justanothernewbie804 | last post by:
hi all. I have a dataset and would like to do something like "select distinct field1, field2 from fields" against the dataset. I do not have the option of creating a new database table and selecting from that table. Nor do I have the option of changing how the dataset is populated. I need to select distinct from the dataset that I have. Any suggestions?
0
9670
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10430
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10000
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9033
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7538
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6776
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5436
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5560
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4111
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.