473,387 Members | 3,750 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,387 software developers and data experts.

Displaying null values in query

I have a Customers Table with the following field names.

C_FirstName
C_LastName
C_MiddleI
..
..
..
..
..

When I run the query to give me all of the Customers I get all the
information I want.
Now I'm trying to use the zoom function in the QBE window by doing the
following.

Customer Name: [C_FirstName]+" "+[C_MiddleI]+" "+[C_LastName]

By doing this I only the the results of those records that contain a
Middle Initial.
How can I go about to get the results of all the records even those
without a middle Initial?

Any help will be appreciated.

Ernie

Jul 19 '07 #1
5 2264
In general you want to use & as the concatenation operator (not +) for 2
reasons:
a) It handles Nulls better
b) It does not get confused with numeric addition.

The difference is that:
"A" & Null = "A"
"A" + Null = Null

You can use that to advantage to get rid of multiple spaces:
Customer Name: [C_FirstName] + " " & [C_MiddleI] + " " & [C_LastName]

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
"ernestb08" <er*******@yahoo.comwrote in message
news:11**********************@m3g2000hsh.googlegro ups.com...
>I have a Customers Table with the following field names.

C_FirstName
C_LastName
C_MiddleI
.
.
.
.
.

When I run the query to give me all of the Customers I get all the
information I want.
Now I'm trying to use the zoom function in the QBE window by doing the
following.

Customer Name: [C_FirstName]+" "+[C_MiddleI]+" "+[C_LastName]

By doing this I only the the results of those records that contain a
Middle Initial.
How can I go about to get the results of all the records even those
without a middle Initial?

Any help will be appreciated.

Ernie
Jul 19 '07 #2
Nulls do not propagate (something + null always equals null). When you use
the "+" operator in concatenation, if any null (no middle initial) is
encountered the entire result will be null.

If you used the & operator to concatenate the string Customer Name:
[C_FirstName] & " " & [C_MiddleI] & " " &[C_LastName]
If the Middle initial were null then an extra space would still be added
between the first and last name which would be undesirable.

By mixing the & and + operators (and wrapping the + strings in parenthesis)
we can eliminate the extra spaces.

Try Customer Name: ([C_FirstName]+" ") & ([C_MiddleI]+" ") & [C_LastName]

If either the first name or middle initial are null then the & operator
concatenates nothing to the string but those fields that have a value are
concatenated.

Len

"ernestb08" <er*******@yahoo.comwrote in message
news:11**********************@m3g2000hsh.googlegro ups.com...
>I have a Customers Table with the following field names.

C_FirstName
C_LastName
C_MiddleI
.
.
.
.
.

When I run the query to give me all of the Customers I get all the
information I want.
Now I'm trying to use the zoom function in the QBE window by doing the
following.

Customer Name: [C_FirstName]+" "+[C_MiddleI]+" "+[C_LastName]

By doing this I only the the results of those records that contain a
Middle Initial.
How can I go about to get the results of all the records even those
without a middle Initial?

Any help will be appreciated.

Ernie

Jul 19 '07 #3
On Jul 19, 8:35 am, "Len Robichaud" <len.robich...@rqwproserv.com>
wrote:
Nulls do not propagate (something + null always equals null). When you use
the "+" operator in concatenation, if any null (no middle initial) is
encountered the entire result will be null.

If you used the & operator to concatenate the string Customer Name:
[C_FirstName] & " " & [C_MiddleI] & " " &[C_LastName]
If the Middle initial were null then an extra space would still be added
between the first and last name which would be undesirable.

By mixing the & and + operators (and wrapping the + strings in parenthesis)
we can eliminate the extra spaces.

Try Customer Name: ([C_FirstName]+" ") & ([C_MiddleI]+" ") & [C_LastName]

If either the first name or middle initial are null then the & operator
concatenates nothing to the string but those fields that have a value are
concatenated.

Len

"ernestb08" <ernest...@yahoo.comwrote in message

news:11**********************@m3g2000hsh.googlegro ups.com...
I have a Customers Table with the following field names.
C_FirstName
C_LastName
C_MiddleI
.
.
.
.
.
When I run the query to give me all of the Customers I get all the
information I want.
Now I'm trying to use the zoom function in the QBE window by doing the
following.
Customer Name: [C_FirstName]+" "+[C_MiddleI]+" "+[C_LastName]
By doing this I only the the results of those records that contain a
Middle Initial.
How can I go about to get the results of all the records even those
without a middle Initial?
Any help will be appreciated.
Ernie- Hide quoted text -

- Show quoted text -
Consider me thick, but I never knew this! Great post!

Jul 19 '07 #4
Jana, you may find this helpful too:
Common errors with Null
at:
http://allenbrowne.com/casu-12.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Jana" <Ba********@gmail.comwrote in message
news:11**********************@o61g2000hsh.googlegr oups.com...
>
... I never knew this! Great post!
Jul 20 '07 #5
On Jul 19, 6:05 pm, "Allen Browne" <AllenBro...@SeeSig.Invalidwrote:
Jana, you may find this helpful too:
Common errors with Null
at:
http://allenbrowne.com/casu-12.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users -http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Jana" <Bauer.J...@gmail.comwrote in message

news:11**********************@o61g2000hsh.googlegr oups.com...


... I never knew this! Great post!- Hide quoted text -

- Show quoted text -
Thanks, nice tips, but I'd already managed that bit, just didn't know
there was a + concatenator that worked differently than the &. I've
always just used the & and programmed to deal with nulls & spaces
elsewise. This little gem of info will definitely come in handy!

A big fan of this group,
Jana

Jul 20 '07 #6

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

Similar topics

0
by: Morten Gulbrandsen | last post by:
-------------- SELECT Version() -------------- +--------------------+ | Version() | +--------------------+ | 5.0.0-alpha-max-nt | +--------------------+ 1 row in set (0.00 sec)
1
by: harsha | last post by:
Dear All, I am using a SQL server database with around 20 columns,all the columns have numeric values, I want to write an SQL statement which does the following: compare each row of the table...
4
by: Ellen Manning | last post by:
Using SQL2000. I want to return the # of columns with non-null values. Here's my query so far: select case when Dx1 is not null then 0 else 1 end + case when Dx2 is not null then 0 else 1 end...
3
by: JOEP | last post by:
What do I need to do to allow an append query to post null values to records in a field of the destination table? Basically I want to allow records with null values to post to the table. The append...
1
by: Edward Koucherian | last post by:
I'm getting the incorrect display value on my DataGrid column. The field is numeric (1) in the SQL database table The Code is txtCol = New DataGridBoolColumn txtCol.MappingName = "MyCol"...
3
by: Sardaukary | last post by:
Hello, >From the following table showing which countries people have been to Name Countries Fred France Fred UK Bill Germany Jack USA
2
by: shar7 | last post by:
Hi, I am new to SQL and I need help to display null value as 0. Problem description: The query is to display Branch Code, Branch Location, Account Type Code, account Type Description and Total...
3
ADezii
by: ADezii | last post by:
Null as it relates to database development is one of life's little mysteries and a topic of total confusion for novices who venture out into the database world. A Null Value is not zero (0), a zero...
5
by: Gilles Ganault | last post by:
Hello I use the prepare/execute combo to generate SQL statements. Is it possible to actually see what PDO creates with prepare()? ======= $sql = "INSERT INTO mytable (id, label) VALUES...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.