if statement in query

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a query that makes a table called products. One of the fields is
called price and another is PN. I can I create an if statement in the
criteria that would multiple price by 2 if PN starts with the letter X?

Something like this:

If [PN] is "X*" then [price] *2 else do nothing.

I'm just not sure how to do it.

Thanks.
 
I am not sure how you plan on using it but I think this is what you want --
IFF [PN] Like "X*", [price] *2, [price])
This doubles [price] if PN starts with the 'X' and uses [price] as is if not
start with 'X'.
 
Use a calculated field in the query -
Price: IIF(Left([PN],1)="X",2*[Price],[Price])
It doesn't actually do nothing if the part number doesn't start with X. It
sets itself to its original value. Watch out for Nulls.
I have a query that makes a table called products. One of the fields is
called price and another is PN. I can I create an if statement in the
criteria that would multiple price by 2 if PN starts with the letter X?

Something like this:

If [PN] is "X*" then [price] *2 else do nothing.

I'm just not sure how to do it.

Thanks.
 
Not sure what you mean by do nothing, keep the price or return 0

To return 0
NewPrice: IIf ([PN] Like "X*" , [price] *2 , 0)

To return the price
NewPrice: IIf ([PN] Like "X*" , [price] *2 , [price])
 

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

Back
Top