Help needed with update table query

AndyDevine1

Board Regular
Joined
Jun 1, 2006
Messages
172
Hi there

I have a table called "Current week" which contains a field called "Current week". This always contains one row of information, for this example lets say the current week is "week 20"

In my "master database" table I have an "all weeks" field and a "tag" field

In "all weeks" I have:
Row 1 = "2013 week 19"
Row 2 = "2013 week 20"
Row 3 = "2014 week 19"
Row 4 = "2014 week 20"
etc

What do I need to write an update query to update the "tag" field based on:

..if "all weeks" field contains "current week" then tag it with "yes", otherwise tag it with "no"?

ie to get...

All weeks (field)...tag (field)
Row 1 = "2013 week 19"...no
Row 2 = "2013 week 20"...yes
Row 3 = "2014 week 19"...no
Row 4 = "2014 week 20"...yes

Many thanks
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
You could do a two stepper, first "reset" the weeks to all no's, then update the current weeks to yes:
Code:
UPDATE [Master Database] SET [all week] = "no";
UPDATE [Master Database] SET [all week] = "yes" WHERE [all week] = (SELECT [Current week] FROM [Current week]);

It may (or may not be) faster to do it all at once - try it and see. You might do more in one pass even though using the IIF function requires extra processing:
Code:
UPDATE [Master Database] SET [all week] = IIF([all week] = (SELECT [Current week] FROM [Current week]), "yes", "no");

strictly from the point of view of database design you don't need the tag field since you can always join on the current week table to identify the current week - this means you just work with your queries using both tables. Be sure that all fields used in query criteria are indexed. For Access I would try not to have a table with the same name as a field just as a precaution.
 
Upvote 0
Thanks for this...but isn't this code based on where they are the same rather than where it contains?

As all weeks string contains eg "2013 week 19" or "2013 week 22" etc...and Current Week contains "week 19" etc?

Please advise

Many thanks
 
Upvote 0
I was using this to create new table..as found updating too difficult...

Tag2: IIf([Master Database].[All Weeks] Like "*[Current Week].[Current Week] *","yes","no")

This doesnt work...can you let me know why?

Appreciate your help

Many thanks
 
Upvote 0
Hi,
There's a space in what you posted so that would cause it to fail. Also I wouldn't use Like here since you can use equality. Your questions aren't clear to me (unless your records contain more data than you have shown in your post - have you posted enough sample data to describe the problem?).
ξ
 
Upvote 0

Forum statistics

Threads
1,215,047
Messages
6,122,858
Members
449,096
Latest member
Erald

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