View Full Version : help w/ calculated fields in a query


Tekture
12-19-2008, 04:51 AM
So, I have this query...
This expression works fine:
Expr9: Nz(DateDiff("d",[Closed Externally],[Cert Returned to HR]),0)

However, this one does not: (the expression itself works, it's just that the [] + [] is concantanating and not adding)
Expr13: IIf(Nz(DateDiff("d",[Closed Externally],[Cert Returned to HR]),0)="0",[Expr7]+[Expr8],[Expr9])

What's the deal?

In fact... i can't even get this to work:
[Expr1] + [Expr2]
Instead of adding, it concentanates.

I tried putting Sum(), Add(), tried deleting the bracets and putting quotes.

What am i missing?

Uncle Gizmo
12-19-2008, 05:42 AM
Try using & instead of +

MSAccessRookie
12-19-2008, 05:45 AM
So, I have this query...
This expression works fine:
Expr9: Nz(DateDiff("d",[Closed Externally],[Cert Returned to HR]),0)

However, this one does not: (the expression itself works, it's just that the [] + [] is concantanating and not adding)
Expr13: IIf(Nz(DateDiff("d",[Closed Externally],[Cert Returned to HR]),0)="0",[Expr7]+[Expr8],[Expr9])

What's the deal?

In fact... i can't even get this to work:
[Expr1] + [Expr2]
Instead of adding, it concentanates.

I tried putting Sum(), Add(), tried deleting the bracets and putting quotes.

What am i missing?



Some Observations:

Your Nz() Statement returns 0, and you are comparing it to "0". This will always return a FALSE response. Try changing it to 0.
What is the definition of [Expr7], [Expr8], and [Expr9]? If [Expr7] + [Expr8] Concatenates the Fields, then they probably are TEXT. Changing [Expr7] + [Expr8] to cInt([Expr7]) + cInt([Expr8]) may resolve the issue. You may also need to change [Expr9] to cInt([Expr9]).

Uncle Gizmo
12-19-2008, 05:46 AM
>>>In fact... i can't even get this to work:
[Expr1] + [Expr2]<<

In this case you may have to convert the [Expr1] like so:

CInt([Expr1]) or possibly long or double depending.

Brianwarnock
12-19-2008, 08:06 AM
Some Observations:

Your Nz() Statement returns 0, and you are comparing it to "0". This will always return a FALSE response. Try changing it to 0.


Not true, Nz actually returns a string so logically "0" is correct , however Access accepts "0" or 0

Brian

Tekture
12-19-2008, 01:11 PM
sorry for double posting this question, my internet froze somewhere in between all that.

I will try these suggestions and post my results. Thank you so much for your help.