Place a value in one field based upon the value of another field

creyn

Board Regular
Joined
Sep 16, 2016
Messages
127
How can I write in the query if one field is "Yes" have another field = "" or if the field is "" then have another field = "No"?

I tried this:

=IIf([PQRS Data].Value = "Yes", [PQRS Data].Problems = "", "No")


This does not work. Can anyone assist me with clearing this up?

Thank you
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
You cannot set the value of fields via a query unless you do an Update query.
Basically, calculations which you can run/call at any time should typically NOT be stored in a table field. They should just be calculated fields in a query.
General rule of thumb: Do not store anything in a field which can easily be calculated.

If you are still unclear as to what you should be doing, please explain to us in detail what you are trying to do, and we will try to come up with the suggested way of doing it.
 
Last edited:
Upvote 0
This is what I am trying to do.

=IIf([Field1] = "Yes", [Filed2] = "", "No")

Can I do this without doing an update?
 
Upvote 0
If Field2 is a field in your table that you want to permanently update, you MUST use an UPDATE Query.
You cannot update field values using a SELECT query. SELECT queries just return data.
 
Upvote 0
I think you mean the other way around. You cannot nest an UPDATE Query inside a SELECT Query, but you can nest a SELECT Query inside an UPDATE query.
Though I am not sure why you need to do that. It should be pretty straightforward, since it is updating one field in a single table based on criteria in another field within that same table.
 
Upvote 0
Below is my query. I cannot update the PQRS Data.Problems until the PQRS Data.Value has it value. This is part of the confusion I am having.

SELECT [PQRS Data].[Chart #] AS [Patient ID],
[PQRS Data].[Admit Dt] AS DOS,
[PQRS Data].[Visit ID],
=IIf([PQRS Data].Value = "Reporting Met And Performance Met" Or [PQRS Data].Value = "Advanced Care Planning - first 30 minutes" Or [PQRS Data].Value = "Advanced Care Planning - each additional 30 minutes", "Yes","") AS Met,
[PQRS Data].Problems,
"N/A" AS Excluded
FROM [PQRS Data]
GROUP BY [PQRS Data].[Chart #], [PQRS Data].[Admit Dt], [PQRS Data].[Visit ID], [PQRS Data].Problems, "N/A", [PQRS Data].Value;
 
Upvote 0
This is how I am writing the query now

UPDATE [PQRS Data] SET [PQRS Data].Problems = ""
WHERE [PQRS Data].Value = "Reporting Met And Performance Met" Or [PQRS Data].Value = "Advanced Care Planning - first 30 minutes" Or [PQRS Data].Value = "Advanced Care Planning - each additional 30 minutes"
FROM
(
SELECT [PQRS Data].[Chart #] AS [Patient ID],
[PQRS Data].[Admit Dt] AS DOS,
[PQRS Data].[Visit ID],
=IIf([PQRS Data].Value = "Reporting Met And Performance Met" Or [PQRS Data].Value = "Advanced Care Planning - first 30 minutes" Or [PQRS Data].Value = "Advanced Care Planning - each additional 30 minutes", "Yes","") AS Met,
[PQRS Data].Problems,
"N/A" AS Excluded
FROM [PQRS Data]
GROUP BY [PQRS Data].[Chart #], [PQRS Data].[Admit Dt], [PQRS Data].[Visit ID], [PQRS Data].Problems, "N/A", [PQRS Data].Value
) t
WHERE [PQRS Data].Problems = t.Problems;
 
Upvote 0
And is it working?

If not, please explain (in plan English), exactly what records you are trying to update to what, and what the conditions are.
I am always very leery of trying to decipher what someone is trying to do by reverse engineering their code, especially when I don't know if the code is faulty or not, and really does what they want it to.
 
Upvote 0

Forum statistics

Threads
1,221,771
Messages
6,161,847
Members
451,723
Latest member
Rachetsely

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top