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. 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
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.
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.
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/
"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
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!
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?
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/
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/ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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?...
|
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,...
|
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...
|
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...
|
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...
|
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...
|
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 =...
|
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...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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,...
|
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...
|
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...
|
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...
| |