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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

use update query with "OR" statment

Status
Not open for further replies.

ChewDinCompSci

Technical User
Dec 29, 2004
40
CA
I am trying to update fields in a column called FuelWord with the word "Gasoline" or "Diesel" based on the value of another field in the same record, FuelType which has a value of "1" or "2". This is the SQL I have tried:

UPDATE tbl_FuelUsage SET tbl_FuelUsage.FuelWord = "Gasoline"
WHERE ((([tbl_FuelUsage].[FuelType])="1")) Or ((([tbl_FuelUsage].[FuelWord])="Diesel"));

When I first viewed the data it appeared to work. After running the update query a second time every field under the column FuelWord changed to "Gasoline"

What's wrong??? Any help is much appreciated.

MatChew

codename: vba4dumbE
 
UPDATE tbl_FuelUsage SET FuelWord = IIf(FuelType="1","Gasoline","Diesel")
WHERE FuelType In ("1","2")

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
I'm a little confused about what you're trying to do, but I think it is easily done in the query by design grid.

If fueltype 1 is gasoline:

New Update query
add fields fuelword and fueltype
criteria row of fueltype = 1
update to row of fuelword ="gasoline"

Then run it again on the criteria that = diesel
i.e. fueltype = 2 in criteria row
"Diesel" in update to row
 
That did not work for me. I still got back all values of "Gasoline" in the table column FuelWord. Just to clarify dpav29, I am trying to update the fields in a column with either the word Gasoline or Diesel based on the value of another field in a different column in the same table.
Gasoline = 1, Diesel = 2

ie.

FuelType FuelWord
1 Gasoline
1 Gasoline
1 Gasoline
2 Diesel
2 Diesel
1 Gasoline

codename: vba4dumbE
 
Sorry if this was still too vague the column FuelWord contains all blank [/] fields. I need them filled with either Gasoline or Diesel depending on if colum FuelType is a "1" or "2"

codename: vba4dumbE
 
Have you tried my suggestion ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
PHV, I tried your suggestion and got the same result.

codename: vba4dumbE
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top