473,387 Members | 3,781 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.

Why does DSUM function is returning me a string not a number

222 100+
Expand|Select|Wrap|Line Numbers
  1. nz(DSum("[quantityindetail]*[purchaseprice]-[quantityindetail]*[purchaseprice]*DiscPurchasedetail*0.01","Purchasedetail","[purchaseid]= '" & [Purchaseid] & "'"),0) AS sub_total
  2.  
  3.  nz(DSum("[vatvaluePurchasedetail]","Purchasedetail","[purchaseid]= '" & [Purchaseid] & "'"),0) AS vat_sum 
I am running this two functions in a query.

What I am trying to do is adding

Expand|Select|Wrap|Line Numbers
  1. vat_sum + sub_total as grandtotal
it is working but as string. example 25+5=255

How may I tell the DSUM to return me a number value in place of string ?
any idea it would be appreciated

Thank you in advance

WASSIM S DACCACHE
Nov 17 '08 #1
4 4689
missinglinq
3,532 Expert 2GB
What Datatypes are vat_sum and sub_total?

Linq ;0)>
Nov 17 '08 #2
Stewart Ross
2,545 Expert Mod 2GB
Hi Wassim. It's not DSum that returns the string - it's the Nz function. You can convert each Nz string value back to a number using one of the type conversion functions as necessary:

Expand|Select|Wrap|Line Numbers
  1. CCur(Nz(DSum..., 0)) ' convert to currency value
  2. CDbl(Nz(DSum..., 0)) ' convert to double-precision floating point
  3. CLng(Nz(DSum..., 0)) ' convert to long integer
or you can use the Val function to take the numeric value of each string instead

Expand|Select|Wrap|Line Numbers
  1. Val(Nz(DSum..., 0))
However, as Linq has pointed out you should ensure that the type of the variables or fields you are assigning these values to is correct. Access normally does type conversion 'on the fly' - if the result is assigned to a double-precision value, say, then Access would convert the Nz results to floating-point numbers before performing the sum. It suggests you have a text result type somewhere.

-Stewart
Nov 17 '08 #3
wassimdaccache
222 100+
Hi Wassim. It's not DSum that returns the string - it's the Nz function. You can convert each Nz string value back to a number using one of the type conversion functions as necessary:

Expand|Select|Wrap|Line Numbers
  1. CCur(Nz(DSum..., 0)) ' convert to currency value
  2. CDbl(Nz(DSum..., 0)) ' convert to double-precision floating point
  3. CLng(Nz(DSum..., 0)) ' convert to long integer
or you can use the Val function to take the numeric value of each string instead

Expand|Select|Wrap|Line Numbers
  1. Val(Nz(DSum..., 0))
However, as Linq has pointed out you should ensure that the type of the variables or fields you are assigning these values to is correct. Access normally does type conversion 'on the fly' - if the result is assigned to a double-precision value, say, then Access would convert the Nz results to floating-point numbers before performing the sum. It suggests you have a text result type somewhere.

-Stewart
Thank you for your reply. I used the VAL () function and it is converting the string to number.

but I didn't understand why it is replying me a string since i used the dsum function without the NZ () function also the dsum function is doing the sum of fields that datatypes are double.

regards,
Nov 18 '08 #4
missinglinq
3,532 Expert 2GB
It's just one of many quirks in Access! When used in a query, Nz() always returns a string!

Linq ;0)>
Nov 19 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: lawrence | last post by:
I'm learning Javascript. I downloaded a script for study. Please tell me how the variable "loop" can have scope in the first function when it is altered in the second function? It is not defined...
1
by: Rolan | last post by:
I'm using Access 97 and need some assistance in sorting out a proper DSum expression. It relates to a subform (sfrmCost) from which I'm wanting to extract the grand total of any and all data rows...
1
by: Dalan | last post by:
I have tried both methods of using DSum and creating a Function to address summing some number columns, but to no avail. Since this has been a popular topic over the years, I'm sure I'll receive...
4
by: John Baker | last post by:
Hi: I have a form, and wish to show on the form the current total for a single field on a table. I have set this up thus: =DSum(,!) in an unbound text field. These are correct field and table...
2
by: GD | last post by:
tblFoo FooId Name Number 1 One 1 2 Two 2 3 Three 3 The Following query produces the results I want, but it is not updatable. I need at least the...
3
by: beppe005 | last post by:
I would like to calculate a total for all the field with the same in a query. I don't know how to set the "criteria" for this dsum function, it should be something like = but it doesn't make...
12
by: Newbie | last post by:
how can i call an oracle function to get data without using a select statement or stored procedures? given a project_no, i need to call the function: ops$sqltime.pa_new_job_no_fn which will...
6
by: ckpoll2 | last post by:
Hi, I have made a report that has a query as its record source. I put a text box in there that I want to run a dsum function off of a different query. The criteria that I need to use is that it...
3
by: technocraze | last post by:
Hi community experts, I am having an isue with Dsum function that is used to count the total number for a particular field (intake) at the textbox afterupdate event with condition/ criteria...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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
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: 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:
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
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...

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.