473,416 Members | 1,784 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

MS ACCESS 2002: How to DESIGN a semi-complex QUERY EXPRESSION FIELD???

Ok, my Access 2002 language writing skills are VERY rusty,. I would
know how to do what I need using SQL Server's "Coalesce' function, but
I don't have that available to me in the Access 2002 database I'm
currently programming.

....So could someone advise me how to add an Expression Field to a
Access 2002 Query that will reflect the following:

Imagine I want a field that derives from Fields in a table I've called
tblContacts. tblContacts has fields called FirstName, LastName and
CompanyName.

Here's what I want the Expression Field (which I'll call 'FullName')
to reflect:

1) If neither FirstName nor LastName are NULL, then FullName should
be the equivalent of LastName, FirstName (that's the LastName followed
by a comma followed by the FirstName.

2) If LastName is NULL, but FirstName is not NULL, then FullName
should be the equivalent of FirstName.

3) If both LastName and FirstName are NULL, and CompanyName is not
null, then FullName should be the equivalent of CompanyName.

So that's it. How would you 'design' this FullName field in Access'
Query Design view?

Thanks in advance.
Sep 13 '06 #1
9 3035
Alan Mailer <cl**********@earthlink.netwrote in
news:49********************************@4ax.com:
Ok, my Access 2002 language writing skills are VERY rusty,. I
would know how to do what I need using SQL Server's "Coalesce'
function, but I don't have that available to me in the Access
2002 database I'm currently programming.

...So could someone advise me how to add an Expression Field
to a Access 2002 Query that will reflect the following:

Imagine I want a field that derives from Fields in a table
I've called tblContacts. tblContacts has fields called
FirstName, LastName and CompanyName.

Here's what I want the Expression Field (which I'll call
'FullName') to reflect:

1) If neither FirstName nor LastName are NULL, then FullName
should be the equivalent of LastName, FirstName (that's the
LastName followed by a comma followed by the FirstName.

2) If LastName is NULL, but FirstName is not NULL, then
FullName should be the equivalent of FirstName.

3) If both LastName and FirstName are NULL, and CompanyName is
not null, then FullName should be the equivalent of
CompanyName.

So that's it. How would you 'design' this FullName field in
Access' Query Design view?

Thanks in advance.
You didn't specify a case where firstname is null but lastname
is not. The code below will show lastname,

Fullname: nz(Lastname+", " & Firstname, CompanyName)
Note the use of + and & as concatenation operators. + propagates
the null, (null + text = null), the & does not propagate the
null ( null & text = text). the Access nz() function handles
(value, alternate when value is null).

--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com

Sep 14 '06 #2
On 14 Sep 2006 00:14:28 GMT, Bob Quintal <rq******@sPAmpatico.ca>
wrote:
>Alan Mailer <cl**********@earthlink.netwrote in
news:49********************************@4ax.com :
>Ok, my Access 2002 language writing skills are VERY rusty,. I
would know how to do what I need using SQL Server's "Coalesce'
function, but I don't have that available to me in the Access
2002 database I'm currently programming.

...So could someone advise me how to add an Expression Field
to a Access 2002 Query that will reflect the following:

Imagine I want a field that derives from Fields in a table
I've called tblContacts. tblContacts has fields called
FirstName, LastName and CompanyName.

Here's what I want the Expression Field (which I'll call
'FullName') to reflect:

1) If neither FirstName nor LastName are NULL, then FullName
should be the equivalent of LastName, FirstName (that's the
LastName followed by a comma followed by the FirstName.

2) If LastName is NULL, but FirstName is not NULL, then
FullName should be the equivalent of FirstName.

3) If both LastName and FirstName are NULL, and CompanyName is
not null, then FullName should be the equivalent of
CompanyName.

So that's it. How would you 'design' this FullName field in
Access' Query Design view?

Thanks in advance.
You didn't specify a case where firstname is null but lastname
is not. The code below will show lastname,

Fullname: nz(Lastname+", " & Firstname, CompanyName)
Note the use of + and & as concatenation operators. + propagates
the null, (null + text = null), the & does not propagate the
null ( null & text = text). the Access nz() function handles
(value, alternate when value is null).

--
Bob Quintal

PA is y I've altered my email address.

Thank you Bob for this interesting solution. It got me almost all the
way to where I need to be; except for handling (as you mentioned) the
one condition I left out of my original message:

4) If LastName is not null and FirstName is Null, then FullName should
be the equivalent of LastName.

....By the way, one other quibble, your solution deals with condition
#2...
>2) If LastName is NULL, but FirstName is not NULL, then
FullName should be the equivalent of FirstName.
....in a way that is not optimal for me. (Please understand, I'm not
criticising your help, I really appreciate it). However, using your
solution, when the above condition is met FullName becomes
"FirstName," (in other words, the FirstName followed by an undesired
comma). Given this discovery, let me throw out a 5th rule I'd like
FullName to follow:

4) A comma should only appear in the FullName expression if both
LastName and FirstName are NOT NULL.

Could you (or anyone else reading this) help me to correct the
otherwise brilliant "Fullname: nz(Lastname+", " & Firstname,
CompanyName)" solution in a way that will accomodate the two new
conditions I've added in this message?

I'm learning a lot from this. Again, thank you for your help.

Sep 14 '06 #3
By way of update, here's how I've written the Query Expression I've
been asking about:

FullName: IIf(Not IsNull([FirstName]) And Not
IsNull([LastName]),[LastName] & ", " & [FirstName],IIf(Not
IsNull([LastName]),[LastName],IIf(Not
IsNull([FirstName]),[FirstName],[Company])))

....This appears to be giving me what I want, but it seems awfully
convoluted, not read-able, hard to write, etc...

I'm still open to hearing a cleaner way of going about this. In the
meantime though, thanks to all who have lent a hand.

On Thu, 14 Sep 2006 03:50:31 GMT, Alan Mailer
<cl**********@earthlink.netwrote:
>On 14 Sep 2006 00:14:28 GMT, Bob Quintal <rq******@sPAmpatico.ca>
wrote:
>>Alan Mailer <cl**********@earthlink.netwrote in
news:49********************************@4ax.co m:
>>Ok, my Access 2002 language writing skills are VERY rusty,. I
would know how to do what I need using SQL Server's "Coalesce'
function, but I don't have that available to me in the Access
2002 database I'm currently programming.

...So could someone advise me how to add an Expression Field
to a Access 2002 Query that will reflect the following:

Imagine I want a field that derives from Fields in a table
I've called tblContacts. tblContacts has fields called
FirstName, LastName and CompanyName.

Here's what I want the Expression Field (which I'll call
'FullName') to reflect:

1) If neither FirstName nor LastName are NULL, then FullName
should be the equivalent of LastName, FirstName (that's the
LastName followed by a comma followed by the FirstName.

2) If LastName is NULL, but FirstName is not NULL, then
FullName should be the equivalent of FirstName.

3) If both LastName and FirstName are NULL, and CompanyName is
not null, then FullName should be the equivalent of
CompanyName.

So that's it. How would you 'design' this FullName field in
Access' Query Design view?

Thanks in advance.
You didn't specify a case where firstname is null but lastname
is not. The code below will show lastname,

Fullname: nz(Lastname+", " & Firstname, CompanyName)
Note the use of + and & as concatenation operators. + propagates
the null, (null + text = null), the & does not propagate the
null ( null & text = text). the Access nz() function handles
(value, alternate when value is null).

--
Bob Quintal

PA is y I've altered my email address.


Thank you Bob for this interesting solution. It got me almost all the
way to where I need to be; except for handling (as you mentioned) the
one condition I left out of my original message:

4) If LastName is not null and FirstName is Null, then FullName should
be the equivalent of LastName.

...By the way, one other quibble, your solution deals with condition
#2...
>>2) If LastName is NULL, but FirstName is not NULL, then
FullName should be the equivalent of FirstName.

...in a way that is not optimal for me. (Please understand, I'm not
criticising your help, I really appreciate it). However, using your
solution, when the above condition is met FullName becomes
"FirstName," (in other words, the FirstName followed by an undesired
comma). Given this discovery, let me throw out a 5th rule I'd like
FullName to follow:

5) A comma should only appear in the FullName expression if both
LastName and FirstName are NOT NULL.

Could you (or anyone else reading this) help me to correct the
otherwise brilliant "Fullname: nz(Lastname+", " & Firstname,
CompanyName)" solution in a way that will accomodate the two new
conditions I've added in this message?

I'm learning a lot from this. Again, thank you for your help.
Sep 14 '06 #4
Alan Mailer <cl**********@earthlink.netwrote in
news:1q********************************@4ax.com:
By way of update, here's how I've written the Query Expression
I've been asking about:

FullName: IIf(Not IsNull([FirstName]) And Not
IsNull([LastName]),[LastName] & ", " & [FirstName],IIf(Not
IsNull([LastName]),[LastName],IIf(Not
IsNull([FirstName]),[FirstName],[Company])))

...This appears to be giving me what I want, but it seems awfully
convoluted, not read-able, hard to write, etc...
Nz(Mid(("12" + LastName) & (", " + FirsName), 3), Company)

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Sep 14 '06 #5
"David W. Fenton" <XX*******@dfenton.com.invalidwrote in
news:Xn**********************************@127.0.0. 1:
Alan Mailer <cl**********@earthlink.netwrote in
news:1q********************************@4ax.com:
>By way of update, here's how I've written the Query
Expression I've been asking about:

FullName: IIf(Not IsNull([FirstName]) And Not
IsNull([LastName]),[LastName] & ", " & [FirstName],IIf(Not
IsNull([LastName]),[LastName],IIf(Not
IsNull([FirstName]),[FirstName],[Company])))

...This appears to be giving me what I want, but it seems
awfully convoluted, not read-able, hard to write, etc...

Nz(Mid(("12" + LastName) & (", " + FirsName), 3), Company)
Wow, that is clever.
--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com

Sep 14 '06 #6
On Thu, 14 Sep 2006 16:17:54 -0500, "David W. Fenton"
<XX*******@dfenton.com.invalidwrote:
>Alan Mailer <cl**********@earthlink.netwrote in
news:1q********************************@4ax.com :
>By way of update, here's how I've written the Query Expression
I've been asking about:

FullName: IIf(Not IsNull([FirstName]) And Not
IsNull([LastName]),[LastName] & ", " & [FirstName],IIf(Not
IsNull([LastName]),[LastName],IIf(Not
IsNull([FirstName]),[FirstName],[Company])))

...This appears to be giving me what I want, but it seems awfully
convoluted, not read-able, hard to write, etc...

Nz(Mid(("12" + LastName) & (", " + FirsName), 3), Company)
Thank you for this suggestion. I'll try it today.

To my surprise, there is no online explanation for "Nz" in Access 2002
online help (at least none that I could find). If you (or anyone else
reading this) have another moment, could you explain to me exactly
what is being evaluated (and processed) in the statement you've
suggested? Don't be afraid of being verbose in your explanation, the
more detail the better. I say this because someone was kind enough to
attempt a shorthand explanation in an earlier message and I have to
admit I still didn't fully grasp what exactly (piece-by-piece) was
going on in the statement.

Thanks again for everyone's help!
Sep 15 '06 #7
How about I'll go one better and post my own explanation of what I
*think* the above expression means... and have someone tell me if (and
where) I'm wrong.

As an evaluation of the following Access query Expression

FullName: Nz(Mid(("12"+[LastName]) & (", "+[FirstName]),3),[Company])

....Here's my dissection:

Nz() :
The 'Nz' part will make sure that the first NON-NULL string in the
statement will be returned. In our current example, that will be one
of the following values:
- Mid(("12"+[LastName]) & (", "+[FirstName]),3)
- [Company]
Mid() :
("12"+[LastName]) & (", "+[FirstName]),3)
The 'Mid' statement above will start the resulting string from the 3rd
character in the string. For example:
- "12Smith, John" will become "Smith, John".
- "12Smith" will become "Smith".
- ", John" will become "John".
,[Company]) :
If the above 'Mid' statement evaluates as Null, Nz will cause
[Company] to be the result of the expression.
....Have I got this right?
Sep 15 '06 #8
Bob Quintal <rq******@sPAmpatico.cawrote in
news:Xn**********************@66.150.105.47:
"David W. Fenton" <XX*******@dfenton.com.invalidwrote in
news:Xn**********************************@127.0.0. 1:
>Alan Mailer <cl**********@earthlink.netwrote in
news:1q********************************@4ax.com :
>>By way of update, here's how I've written the Query
Expression I've been asking about:

FullName: IIf(Not IsNull([FirstName]) And Not
IsNull([LastName]),[LastName] & ", " & [FirstName],IIf(Not
IsNull([LastName]),[LastName],IIf(Not
IsNull([FirstName]),[FirstName],[Company])))

...This appears to be giving me what I want, but it seems
awfully convoluted, not read-able, hard to write, etc...

Nz(Mid(("12" + LastName) & (", " + FirsName), 3), Company)

Wow, that is clever.
I didn't originate it. But I can't say that I remember who came up
with it -- it was one of the regulars who isn't around much any
more, someone much cleverer than I.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Sep 15 '06 #9
Alan Mailer <cl**********@earthlink.netwrote in
news:c9********************************@4ax.com:
How about I'll go one better and post my own explanation of what I
*think* the above expression means... and have someone tell me if
(and where) I'm wrong.

As an evaluation of the following Access query Expression

FullName: Nz(Mid(("12"+[LastName]) & (",
"+[FirstName]),3),[Company])

...Here's my dissection:

Nz() :
The 'Nz' part will make sure that the first NON-NULL string in the
statement will be returned. In our current example, that will be
one of the following values:
- Mid(("12"+[LastName]) & (", "+[FirstName]),3)
- [Company]

Mid() :
("12"+[LastName]) & (", "+[FirstName]),3)
The 'Mid' statement above will start the resulting string from the
3rd character in the string. For example:
- "12Smith, John" will become "Smith, John".
- "12Smith" will become "Smith".
- ", John" will become "John".

,[Company]) :
If the above 'Mid' statement evaluates as Null, Nz will cause
[Company] to be the result of the expression.
...Have I got this right?
Yep.

You did leave out that in the Mid():

Null & Null

will return Null.

But I assume you understood that.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Sep 15 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

33
by: Joe | last post by:
I'm designing a company website. I'm relatively new to CSS and I'm having trouble creating what seems to me a very simple design: - body background: fixed full page image - banner: fixed, 100...
20
by: John | last post by:
Hi, I've recently upgraded from Access 97 to Access 2002 & the performance basically stinks. I have tried the following items listed below but it has only had a minor impact: 1) Upgraded Jet...
14
by: wolftor | last post by:
1) Is there a free runtime version of Access available that is more recent than the one for Access 2000? 2) If I create an application (MDE) in A2K, will it run on all later versions of Access?...
13
by: Noesis Strategy | last post by:
When I ordered my new laptop, Sony didn't offer Access 2003 in its bundles. Recently, I have begun to design Access databases using an copy of Access 2002 from my previous laptop. It works fine,...
0
by: Malcolm Cook | last post by:
I've discovered: Using "File > Print Preview" in a form's datasheet view with a server Filter crashes access after previewing... ....that is, unless ServerFilterByForm has been turned off...
5
by: Lakbir Dhillon | last post by:
We converted our databases from Access 97 to Access 2002 (only the MDB files, not the MDW file). In addition we ported the Access application from a Citrix NT server to a Citrix XP server. We...
2
by: Bruce Dodds | last post by:
I will be doing an app for a nonprofit. It would be useful for them to have a good entry-level book on Access so that they don't have to pay someone to design all their queries and reports. I'm not...
8
by: David Kistner | last post by:
I'm fairly new to Access (I've worked with Oracle and MySQL in the past). I was asked to build an application for a small office and told that I had to use Access 2002. I was VERY uncomfortable...
35
by: deko | last post by:
Do I get more scalability if I split my database? The way I calculate things now, I'll be lucky to get 100,000 records in my Access 2003 mdb. Here some math: Max mdb/mde size = 2000 x 1024 =...
47
by: ship | last post by:
Hi We need some advice: We are thinking of upgrading our Access database from Access 2000 to Access 2004. How stable is MS Office 2003? (particularly Access 2003). We are just a small...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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...

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.