473,586 Members | 2,472 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

A97 - Experimenting with Nz - getting return values that are strings rather than numbers???

MLH
For example: Nz([LaborCost],0) returns "300" if the value in
[LaborCost] field is 300 (currency data type) and "0" if the value is
zero or null. I get strings in the query output - they are all left
aligned and I cannot add them without first converting them to
values. What might be causing this?
Nov 13 '05 #1
37 2437
MLH
I tested this again, making it as simple as I could. The following
SQL describes a query based on a single table and 2 of its fields.
The first is a long integer type the second is a currency type.

SELECT Nz([VehicleJobID],0) AS Case1, Nz([LaborCost],0) AS Case2
FROM tblENF262Specif icInfo;
The output I get in the query dynaset is STRING type data. I figure
I'm nuts so I ran this modification of the above SQL...
SELECT Nz([VehicleJobID],0) AS Case1, Nz([LaborCost],0) AS Case2,
VarType([Case1]) AS Type1, VarType([Case2]) AS Type2
FROM tblENF262Specif icInfo;

And the output below suggests to me that everything is string...
Case1 Case2 Type1 Type2
1 0 8 8
23 0 8 8
24 0 8 8
26 0 8 8
27 0 8 8
28 0 8 8
29 0 8 8
30 0 8 8
31 0 8 8
32 0 8 8
33 0 8 8
34 0 8 8
36 0 8 8
38 0 8 8
42 0 8 8
72 0 8 8
73 0 8 8
74 0 8 8
77 0 8 8
78 0 8 8
83 0 8 8
85 0 8 8
4 0 8 8
5 0 8 8
6 0 8 8
7 0 8 8
8 0 8 8
9 0 8 8
10 0 8 8
11 0 8 8
12 0 8 8
14 0 8 8
15 0 8 8
16 0 8 8
17 0 8 8
19 0 8 8
20 0 8 8
21 0 8 8
76 0 8 8
82 0 8 8
88 0 8 8
89 0 8 8
80 0 8 8
94 0 8 8
95 507 8 8
84 0 8 8
79 0 8 8
90 0 8 8
91 0 8 8
93 0 8 8
97 0 8 8
96 85 8 8
98 0 8 8
99 0 8 8
104 0 8 8
Nov 13 '05 #2
MLH
To further illustrate the point, I used this SQL to extract and
display the actual table field values AND their Nz processed
equivalents...

SELECT Nz([VehicleJobID],0) AS Case1, Nz([LaborCost],0) AS Case2,
tblENF262Specif icInfo.VehicleJ obID, tblENF262Specif icInfo.LaborCos t
FROM tblENF262Specif icInfo;
Here's the query output...

Case1 Case2 VehicleJobID LaborCost
1 0 1 $0.00
23 0 23
24 0 24
26 0 26
27 0 27
28 0 28
29 0 29
30 0 30
31 0 31
32 0 32
33 0 33
34 0 34
36 0 36
38 0 38
42 0 42
72 0 72
73 0 73
74 0 74
77 0 77
78 0 78
83 0 83
85 0 85
4 0 4
5 0 5
6 0 6
7 0 7
8 0 8
9 0 9
10 0 10
11 0 11
12 0 12
14 0 14
15 0 15
16 0 16
17 0 17
19 0 19
20 0 20
21 0 21
76 0 76
82 0 82
88 0 88
89 0 89
80 0 80
94 0 94
95 507 95 $507.00
84 0 84
79 0 79
90 0 90
91 0 91
93 0 93
97 0 97
96 85 96 $85.00
98 0 98
99 0 99 $0.00
104 0 104 $0.00

The first two columns are both left-aligned
strings. I've gotta be doing something wrong.
Someone please set me straight.
Nov 13 '05 #3

MLH wrote:
For example: Nz([LaborCost],0) returns "300" if the value in
[LaborCost] field is 300 (currency data type) and "0" if the value is
zero or null. I get strings in the query output - they are all left
aligned and I cannot add them without first converting them to
values. What might be causing this?


val(Nz([LaborCost],0))?

I haven't used A97 in a while though.

Nov 13 '05 #4
MLH wrote:
For example: Nz([LaborCost],0) returns "300" if the value in
[LaborCost] field is 300 (currency data type) and "0" if the value is
zero or null. I get strings in the query output - they are all left
aligned and I cannot add them without first converting them to
values. What might be causing this?


Yep. Nz() will generally return a string unless you do something about it.

EX: (to force a number)

=Nz(SomeField, 0) + 0

The addition of zero will convert the string from Nz() back into a numeric
value. If you need a specific numeric type then use the appropriate conversion
function wrapped around the Nz().
--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com
Nov 13 '05 #5
MLH
That's news to me. But then, so is Nz in general. Thx
for the heads up. I'm assuming its OK to wrap it inside
the Val() fn - as opposed to adding zero? I just feel odd
about adding zero to a string. I get a runtime 13 when
I run this in the immediate window: ?0+"harvell"
( type mismatch ) I am old-fashioned. Its a fair call.
xxxxxxxxxxxxxxx xxxxxxxxxxxxxxx xxxxxxxxxxx

Yep. Nz() will generally return a string unless you do something about it.

EX: (to force a number)

=Nz(SomeFiel d, 0) + 0

The addition of zero will convert the string from Nz() back into a numeric
value. If you need a specific numeric type then use the appropriate conversion
function wrapped around the Nz().


Nov 13 '05 #6
It's very unlikely that what you are describing is actually happening.
I would like to see it.

1. Can you post the database somewhere so that it can be downloaded and
this peculiarity examined?

2. While posters have given you solutions for dealing with Nulls, in a
simple Access db it may be unnecessary to do so. Reports deal with
nulls quite effectively. Forms deal with nulls quite effectively. What
else is there? Simple Access is almost always the best Access. Most of
the beginner problems we see here are problems of the neophyte who
feels compelled to improve upon the multi-million dollar 15 years in
the making Access way of doing things. I don't try to improve on this
and I have been using Access for almost all those 15 years; as a
result I have a simple advanced interface that always works.

3. My impression is that almost all the multitide of problems you have
posted here result from your straying from the simple path; this
attracts the Access guru wanna-bes, most of whom should not be giving
advice to anyone and the thread degenerates into a collection of
nonsense. As it does, your confusion expands and your bizarre
suggestions increase.

4. Try asking simple questions without assuming half the answer.

5. The notions of wrapping NZ in Val or of adding to 0 to NZ are quite
strange. I have never seen this suggested before. NZ should work for
you just as it's supposed to work.
When you do unnecessary things your application becomes inefficient.
It's much better for you to solve your problem than to patch it.

So compact, zip and post the damn database!

Nov 13 '05 #7
lylefair wrote:
It's very unlikely that what you are describing is actually happening.
I would like to see it. [snip] 5. The notions of wrapping NZ in Val or of adding to 0 to NZ are quite
strange. I have never seen this suggested before. NZ should work for
you just as it's supposed to work.
When you do unnecessary things your application becomes inefficient.
It's much better for you to solve your problem than to patch it.


What is strange? In a query Nz([FieldName], 0) returns a String in the query's
output. I've tried this with every Number type, Currency, and Dates and in
every case what the query returns is a String. It justifies as a String and it
sorts as a String.

I agree that it *should* work as expected, but that is not what happens.
--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com

Nov 13 '05 #8
I do not see how you can deduce from this that these are strings. I
tried the following:

Select JobID, nz([Jobs]![JobID],0) , IsNumeric(nz([Jobs]![JobID],0))
From Jobs


and for a row in which JobID is null I get:

null 0 -1 (i.e. true)

So the nz() function does produce a zero and not a string.

Nov 13 '05 #9
Jim Devenish wrote:
I do not see how you can deduce from this that these are strings. I
tried the following:

Select JobID, nz([Jobs]![JobID],0) , IsNumeric(nz([Jobs]![JobID],0))
From Jobs


and for a row in which JobID is null I get:

null 0 -1 (i.e. true)

So the nz() function does produce a zero and not a string.


Perhaps, it would be worthwhile to try to learn why Rick and MLH get
strings, and Lyle and Jim get numbers.
I haven't a clue. Is it the version of Access? Is it something we setup
in Options? Is it the phase of the moon?

Ideas here?
Nov 13 '05 #10

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

Similar topics

47
3611
by: Martin DeMello | last post by:
It seems to be a fairly common pattern for an object-modifying method to return None - however, this is often quite inconvenient. For instance def f(lst1, lst2): g((lst1 + lst2).reverse()) # doesn't work! you need to say
3
6516
by: success_ny | last post by:
Does anyone have a code snippet to compare those values so I can sort the array of alpha-numeric values that include both characters and integers in it? I.e., if we have values like 4236 and 123234, I want 4236 to be second because 4 is bigger than 1 rather than using the numeric comparison. The strings can include character values and...
3
3998
by: Steve Weixel | last post by:
I'm having problems getting dates to format the way that I need them to. The problem is that I'm used to the VB6 way of doing things, with which the statement Format(37866, "dd MMM yyyy") would yield the string "02 Sep 2003". If I run the same thing in dotNet, it gives me back the format string, which isn't very useful. It *does* work If I...
18
2254
by: Ed Jay | last post by:
<disclaimer>js newbie</disclaimer> My page has a form comprised of several radio buttons. I want to poll the buttons to determine which button was selected and convert its value to a string. I then want to use the string on the same page. My script is: function checkRadio(field) { for(var i=0; i < field.length; i++) {
16
10955
by: Preben Randhol | last post by:
Hi A short newbie question. I would like to extract some values from a given text file directly into python variables. Can this be done simply by either standard library or other libraries? Some pointers where to get started would be much appreciated. An example text file: ----------- Some text that can span some lines.
6
34904
by: Rico | last post by:
Hello, I'm looking for a way to reference the string name of an enumerator. I know in VB.net you can do "MyEnum.ToString" and get the name instead of the integer value. Is there a way I can do something similar with an Enum created in Access? Alright, here is some air code to explain what I mean Public Enum MyEnum
9
3518
by: CapCity | last post by:
We're rewritting an app using C# 2005 and it needs to read files in netCDF format. A dll is available for this and we've had success in calling its functions, unless it updates strings. We have tried several of the suggestions we've found on-line: Strings, StringBuilders, IntPtr, etc., but haven't been able to exactly pull it off. What seem...
15
1265
by: Szabolcs | last post by:
Newbie question: Why is 1 == True and 2 == True (even though 1 != 2), but 'x' != True (even though if 'x': works)?
11
2827
by: Rahul | last post by:
Hi Everyone, I have seen code in different styles like main(argc,argv) int argc; char **argv; { if(argc != 2) exit(1); else exit(0);
0
7841
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8204
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. ...
0
6617
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...
1
5712
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...
0
3838
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...
0
3869
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2345
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
1
1452
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1184
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.