IF THEN STATEMENT IN UPDATE QUERY

  • Thread starter Thread starter Greg Remaly
  • Start date Start date
G

Greg Remaly

I'm trying to change all of the WS values in a field to LTL but only those
values. I'm having trouble getting the if/then statement to work. I'm
using the following statement in the "Update to:" line,
IIf([FreightType]="WS","LTL"). This isn't giving me the result I desire
because there are other values besides these two values. I realize I'm
missing the false portion, but I don't know what to put for just leave the
value alone. I guess what I want is if the value is WS, change it to LTL,
otherwise, just leave the value alone.

How do I do this?

Thanks so much for any help in advance.

(e-mail address removed)
 
Lynn Trapp's answer is the best solution for updating.

If you want to continue to use the IIF statement (less efficient in an update).

IIF([FreightType] & "" ="WS","LTL",[FreightType])

Added the
& ""
to handle any case where freight type is null.

Also, you could use the above expression in a query, if you don't want to
permanently change the value in the field in the table.

Lynn said:
Update YourTable
Set [FreightType] = "LTL"
Where [FreightType] = "WS";

--
Lynn Trapp
MS Access MVP
www.ltcomputerdesigns.com
Access Security: www.ltcomputerdesigns.com/Security.htm

Greg Remaly said:
I'm trying to change all of the WS values in a field to LTL but only those
values. I'm having trouble getting the if/then statement to work. I'm
using the following statement in the "Update to:" line,
IIf([FreightType]="WS","LTL"). This isn't giving me the result I desire
because there are other values besides these two values. I realize I'm
missing the false portion, but I don't know what to put for just leave the
value alone. I guess what I want is if the value is WS, change it to LTL,
otherwise, just leave the value alone.

How do I do this?

Thanks so much for any help in advance.

(e-mail address removed)
 
Back
Top