Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to use Queries under the condition

Status
Not open for further replies.

wdacc

Technical User
Aug 12, 2002
33
US
I have a problem in my query. In my table, I have input A and B. Sometimes B=0. I want A/B in my query. when B=0, A/B => Blank, other have A/B in 2 decimal.

for instance A=1, B=6; or A=0, B=0
I shold have 0.17 (1/6) and [Blank]
 
IIf(B=0, '', Format(A/B,'0.00')

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
PHV,

Thanks for quick answer! But I got message ["The express you entered has an invalid string" -- A string can be up 2048 long, including opening and closing quotation mark].
 
Sorry for the missing closing paren:
IIf(B=0, '', Format(A/B,'0.00'))

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
PHV,

It is not closing paren issue. I tried adding on closing paran. the problem is ",. I can replace " in any number. But if I use ", it alsway says the message above. I wonder how to express "Blank" after IIf=0,

For example if I use IIF=0, 1, Format([a]/,'0.00'), then I get 1 or 0.17. My purpose is get [Blank] and 0.17.
 
And this ?
IIf(=0, ' ', Format([a]/,'0.00'))

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
PHV,

Thanks so much! I got what I want.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top