472,351 Members | 1,613 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

NZ always returns a zero-length string when used in a query expression?

http://msdn.microsoft.com/library/de...HV05186465.asp

"If the value of the variant argument is Null, the Nz function returns
the number zero or a zero-length string (always returns a zero-length
string when used in a query expression)"

****
How many records are there in FirstTable in which Product Is Null.

SELECT COUNT(*) AS CountofNullProdcut
FROM FirstTable
WHERE Product Is Null

CountofNullProduct = 5

There are five records in FirstTable in which Product is Null.

*****
Variants can be Null, but strings cannot.
Since NZ returns a String it cannot return a Null.

SELECT Count(*) AS CountZLS
FROM [SELECT NZ(Product,Null) AS NZProduct
FROM FirstTable]. AS SubQuery
WHERE SubQuery.NZProduct=""

But CountZLS = 0

NZ(Product,Null) returns a Null.
If it returned a string it would return (we assume) a zero length
string.
But there are no zero length strings in
SELECT NZ(Product,Null) AS NZProduct
FROM FirstTable.
(and none that have a null like string such a "Null" either.)

A Null cannot be a string.
Therefore
NZ ****does not**** always returns a zero-length string when used in a
query expression.

************
I believe that this is more accurate description.
Nz, as noted in the object browser, returns a Variant.
There is no Variant JET Data Type.
JET decides to do Something with the Variant. If it has no strong clues
it does what it always does with data (witness its truncation of memo
fields to 255 character text fields), it treats the data as text.
Say the first (row 1) NZ value (variant) is 2. Why not treat it as
byte? Integer? Long? I suppose the answer is that String is safest.
It's likely to have room for whatever may be returned in row 7869.
However it does not do this until it must. If it creates a new table
there is no Variant field type, so it must make a choice, And it
chooses Text. But a calculated field in a query result, examined in
VBA, will be of type Variant.
************
I think it's better to use explcit type conversion whenever one can.
That practice may make this discussion irrelevant.

Dec 23 '05 #1
10 4402
Actually, the zero length string would be a default if you don't specify
what to return. However, in the example you've given, you have specified
what to return by adding the second argument to the function. Also, telling
it to return Null when the value is Null is kind of a waste of time.

--
Wayne Morgan
MS Access MVP
"Lyle Fairfield" <ly***********@aim.com> wrote in message
news:11*********************@g49g2000cwa.googlegro ups.com...
http://msdn.microsoft.com/library/de...HV05186465.asp

"If the value of the variant argument is Null, the Nz function returns
the number zero or a zero-length string (always returns a zero-length
string when used in a query expression)"

****
How many records are there in FirstTable in which Product Is Null.

SELECT COUNT(*) AS CountofNullProdcut
FROM FirstTable
WHERE Product Is Null

CountofNullProduct = 5

There are five records in FirstTable in which Product is Null.

*****
Variants can be Null, but strings cannot.
Since NZ returns a String it cannot return a Null.

SELECT Count(*) AS CountZLS
FROM [SELECT NZ(Product,Null) AS NZProduct
FROM FirstTable]. AS SubQuery
WHERE SubQuery.NZProduct=""

But CountZLS = 0

NZ(Product,Null) returns a Null.
If it returned a string it would return (we assume) a zero length
string.
But there are no zero length strings in
SELECT NZ(Product,Null) AS NZProduct
FROM FirstTable.
(and none that have a null like string such a "Null" either.)

A Null cannot be a string.
Therefore
NZ ****does not**** always returns a zero-length string when used in a
query expression.

************
I believe that this is more accurate description.
Nz, as noted in the object browser, returns a Variant.
There is no Variant JET Data Type.
JET decides to do Something with the Variant. If it has no strong clues
it does what it always does with data (witness its truncation of memo
fields to 255 character text fields), it treats the data as text.
Say the first (row 1) NZ value (variant) is 2. Why not treat it as
byte? Integer? Long? I suppose the answer is that String is safest.
It's likely to have room for whatever may be returned in row 7869.
However it does not do this until it must. If it creates a new table
there is no Variant field type, so it must make a choice, And it
chooses Text. But a calculated field in a query result, examined in
VBA, will be of type Variant.
************
I think it's better to use explcit type conversion whenever one can.
That practice may make this discussion irrelevant.

Dec 23 '05 #2
I agree. Regardless it is clear that this statement is not true:
"If the value of the variant argument is Null, the Nz function returns
the number zero or a zero-length string (always returns a zero-length
string when used in a query expression)"
Always means always; it does not mean when we are not wasting our time.

Dec 23 '05 #3
Lyle Fairfield <ly***********@aim.com> wrote:
: I agree. Regardless it is clear that this statement is not true:
: "If the value of the variant argument is Null, the Nz function returns
: the number zero or a zero-length string (always returns a zero-length
: string when used in a query expression)"
: Always means always; it does not mean when we are not wasting our time.

OK. I know that I have no business getting into this
Talmudic-sounding discussion among experts, but I had carpal tunnel
surgery this week so I'm even more limited than usual in the things I
can find to amuse me.

This is the phrasing I find in the relevant section of the
Access 2003 VBA Language Reference description of the Nz function:

---begin Access 2003 VBA Language Reference------------------------
Argument Description
-------- -----------
variant A variable of data type Variant.

valueifnull Optional (unless used in a query). A Variant that supplies
a value to be returned if the variant argument is Null. This
argument enables you to return a value other than zero or a
zero-length string.

Note If you use the Nz function in an expression in a query without
using the valueifnull argument, the results will be a zero-length
string in the fields that contain null values.
If the value of the variant argument is Null, the Nz function returns
the number zero or a zero-length string (always returns a zero-length
string when used in a query expression), depending on whether the
context indicates the value should be a number or a string. If the
optional valueifnull argument is included, then the Nz function will
return the value specified by that argument if the variant argument is
Null. When used in a query expression, the NZ function should always
include the valueifnull argument,

If the value of variant isn't Null, then the Nz function returns the
value of variant.
---end Access 2003 VBA Language Reference------------------------

So that 'always returns' text that you quote refers to
what it will return in a query if you don't specify
something different--otherwise you'd have to take it to
mean that it will return that even if you've specified
something else in the valueifnull argument, an argument
that's only discussed in the sentence following the
'always returns' statement.

...always doesn't always mean always

--thelma
(running to hide)
Dec 23 '05 #4
Thelma Lubkin wrote:
...always doesn't always mean always

--thelma
(running to hide)


Humility in smart people is unbecoming.

Dec 23 '05 #5
Lyle Fairfield <ly***********@aim.com> wrote:
: Thelma Lubkin wrote:

:> ...always doesn't always mean always
:>
:> --thelma
:> (running to hide)

: Humility in smart people is unbecoming.

How about convuluted forms of saying 'you're right'?
Dec 23 '05 #6
Thelma Lubkin wrote:
...always doesn't always mean always

--thelma
(running to hide)


Experience is easy to gain but many experienced developers will never
express their ideas well, will never think clearly. You do.

There is no reason for you to be hiding or lurking. Your ideas are as
good as or better than those of most posters in CDMA.

IMO Jan 1, 2006 would be a good date for you to stop hiding. Perhaps
December 24, 2005 would be just as satisfactory.

--
Lyle Fairfield
Dec 23 '05 #7
Thelma Lubkin wrote:
How about convuluted forms of saying 'you're right'?


Zero-Length String

--
Lyle Fairfield
Dec 23 '05 #8
"Lyle Fairfield" <ly***********@aim.com> wrote in
news:11*********************@g14g2000cwa.googlegro ups.com:
I agree. Regardless it is clear that this statement is not true:
"If the value of the variant argument is Null, the Nz function
returns the number zero or a zero-length string (always returns a
zero-length string when used in a query expression)"
Always means always; it does not mean when we are not wasting our
time.


Sorry, but I just don't see your point.

Nz() called without a null-case argument behaves as you said above.

But in this case, a null-case argument was, in fact, supplied, so
your observation above is inapplicable.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Dec 24 '05 #9
"Lyle Fairfield" <ly***********@aim.com> wrote in
news:11********************@g14g2000cwa.googlegrou ps.com:
Thelma Lubkin wrote:
...always doesn't always mean always

--thelma
(running to hide)


Humility in smart people is unbecoming.


The smartest people I've ever known are the ones least convinced of
their own competence.

Lyle, feel free to turn this into an insult directed at me.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Dec 24 '05 #10
Naah! You've been civilized and urbane recently. There is no reason to
insult you.

But since you've given me a free shot I'll save it up to spring on you
when you are unsuspecting and vulnerable, if you don't mind.
No, not really.

I'll just enjoy the peace while it lasts.

Dec 24 '05 #11

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

Similar topics

11
by: Bob Smith | last post by:
question in subject. does the standard say anything about this or is it platform dependent? any advice much appeciated /B
47
by: Jeff Relf | last post by:
Hi All, I plan on using the following C++ code to create nodes with unlimited children: // I would like to declare NodeT like this, // but...
25
by: Mantorok Redgormor | last post by:
Finally, control is returned to the host environment. If the value of status is zero or EXIT_SUCCESS, an implementation-defined form of the status...
48
by: Skybuck Flying | last post by:
Hi, I came across this C code which I wanted to understand etc it looked like this: if (-1) etc It made me wonder what the result would...
3
by: tconkling | last post by:
I have an if statement that looks like this: if(foo(&x) && x > y) ... where the value of x is modified by foo, and the comparison between x...
1
by: Pascual ataeda | last post by:
Can someone tell me a case where Module.GetFields() doesn't return zero FieldInfos? Is there a way to have field that are accesible by the entire...
1
by: Morten Nielsen | last post by:
Does anyone have any idea why I can't get a pixel-value of 255 returned in the code below? Any color-value from 0 up to 254 is returned correctly,...
82
by: quiberon2 | last post by:
Hi, Sorry if it might be a stupid question but what should returns malloc(0) ? void *ptr = malloc(0); I am running gcc 3.3.5 and a non-null...
1
by: MicMic | last post by:
I need to know how count a field that returns a zero or a negative?
11
by: active | last post by:
The code below does much as expected. For example biSize=40 but biClrUsed is always zero!
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....

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.