Adding Different Fields

M

Mangler

Say I have to different recordsets that have the fields:
rsA.Fields.Item("A").Value ,rsB.Fields.Item("B").Value

How would I add those to fields? It may be my inexperience but when I
tried something like

rsA.Fields.Item("A").Value + rsB.Fields.Item("B").Value

didnt work because one of the fields was a empty value. I have about
6 fields i need to add together if a value exists in any of them.

Suggestions?

Respectfully,

Danny
 
M

Mangler

test them first :

If Not IsNull(fielda) and Not IsNull(fieldb) then ....
Tried this, maybe i am wrong here:

<% If Not IsNull(rsR.Fields.Item("price").Value) and Not
IsNull(rsRef.Fields.Item("price").Value) Then Response.Write
rsR.Fields.Item("price").Value + rsRef.Fields.Item("price").Value End
If %>

Keep getting a mismatch error...
 
B

Bob Barrows [MVP]

Mangler said:
Say I have to different recordsets that have the fields:
rsA.Fields.Item("A").Value ,rsB.Fields.Item("B").Value

How would I add those to fields? It may be my inexperience but when I
tried something like

rsA.Fields.Item("A").Value + rsB.Fields.Item("B").Value

didnt work because one of the fields was a empty value. I have about
6 fields i need to add together if a value exists in any of them.
1. Modify the sql statements that produce the recordset to ensure the
fields do not contain Nulls. The details depend on the database you are
using. For example, SQL Server has the COALESCE function that can be
used to return either the value, or 0 if the value is Null.
2. Assign the values to variables (GPB*), check to see if they have
values and, if not, set them to 0 (zero) before adding them


*Good Programming Practice
 
D

Dave Anderson

Mangler said:
Say I have to different recordsets that have the fields:
rsA.Fields.Item("A").Value ,rsB.Fields.Item("B").Value

How would I add those to fields? It may be my inexperience but when I
tried something like

rsA.Fields.Item("A").Value + rsB.Fields.Item("B").Value

didnt work because one of the fields was a empty value. I have about
6 fields i need to add together if a value exists in any of them.

Suggestions?

SQL ISNULL is a good choice to ensure you always have a value in your field:
http://msdn2.microsoft.com/en-us/library/aa933210(SQL.80).aspx

It is also worth pointing out that JScript conditional assignment makes this
quite trivial:

(rsA.Fields("A").Value || DEFAULT_VALUE) + ...

You have to set your default value according to type, of course. For
example:

rs.Fields("Quantity").Value || 0
rs.Fields("Address2").Value || ""
rs.Fields("Validated").Value || false
 
M

Mangler

rs.Fields("Quantity").Value || 0

I tried assigning the defult value like the above example and kept
getting an error saying invalid character. I did however get what I
need done to work. Just put some hidden fields with the recordset as
the value and called a javascript function to add the fields.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,573
Members
45,046
Latest member
Gavizuho

Latest Threads

Top