Help with query Update Access 2013

Mac1206

Board Regular
Joined
Jun 3, 2016
Messages
184
I have a need a update query that will update the Values column for all products_subfamily except "MR TOM", "US" but still update the Values in all other Product_Subfamilies and Blank Product_Subfamiliy in the US which are not MR TOM with the source update table below. Please assist...Thanks in adavance

My Query:

SELECT DISTINCTROW Strat_Price_Tbl.Product_Family, Strat_Price_Tbl.Product_SubFamily, Strat_Price_Tbl.Country
FROM Strat_Price_Tbl INNER JOIN Channel_Value_TBL ON Strat_Price_Tbl.Product_Family = Channel_Value_TBL.PRODUCT_FAMILY
WHERE (((Strat_Price_Tbl.Product_SubFamily) Not In ("MR TOM")) AND ((Strat_Price_Tbl.Country) Not In ("CA")));





CHANNEL_CODEPRODUCT_FAMILYPRODUCT_SUBFAMILYCOUNTRYCURRENCYCHANNEL_VALUE
StoresBarUSUSD0
MarketsBarUSUSD40
MarketsBarMR TOMUSUSD0


<colgroup><col><col><col><col><col><col></colgroup><tbody>
</tbody>
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Usually, you use "DISTINCTROW" when you are trying to weed out duplicates from being returned to a SELECT query.
So, use of that indicates that for each record shown by the query, there may actually be multiple records having those values.
As such, that makes this type on query not Updateable.

If you remove the word "DISTINCTROW", it might be able to be made into an Update Query, provide that there are not other factors going on that would make it not Updateable.
See here for a list of those: Microsoft Access tips: Why is my query read-only?

You may need to re-think what you are trying to do do here.
 
Upvote 0
I have a need a update query that will update the Values column for all products_subfamily except "MR TOM", "US" but still update the Values in all other Product_Subfamilies and Blank Product_Subfamiliy in the US which are not MR TOM with the source update table below. Please assist...Thanks in adavance

My Query:

SELECT DISTINCTROW Strat_Price_Tbl.Product_Family, Strat_Price_Tbl.Product_SubFamily, Strat_Price_Tbl.Country
FROM Strat_Price_Tbl INNER JOIN Channel_Value_TBL ON Strat_Price_Tbl.Product_Family = Channel_Value_TBL.PRODUCT_FAMILY
WHERE (((Strat_Price_Tbl.Product_SubFamily) Not In ("MR TOM")) AND ((Strat_Price_Tbl.Country) Not In ("CA")));





CHANNEL_CODEPRODUCT_FAMILYPRODUCT_SUBFAMILYCOUNTRYCURRENCYCHANNEL_VALUE
StoresBarUSUSD0
MarketsBarUSUSD40
MarketsBarMR TOMUSUSD0

<tbody>
</tbody>
When I run it as Select to ensure it returns the same number of records without the Update Table Joined, it's fine but when I join the Update Table...the records increase from 1140 to 3420 without even joining the tbl???? I'm Joining on Product_Family and Country...
 
Last edited:
Upvote 0
If joining two tables results in an increase of records, it usually means that you either have a one-to-many relationship or a many-to-many relationship.
If you do not think this should be the case (and you think that you have a one-to-one relationship), then that means that there is a problem with your Join. Sometimes, more than one field is needed in your Join.

It might be best for us to see what you are trying to do if you can do the following:
1. Post sample data from your Strat_Price_Tbl table
2. Post sample data from your Channel_Value_TBL table
3. Post your expected results, based on the samples provided above
 
Upvote 0
This is the latest query which gives the right amount of rows returned but no Channel_Value update...


STRAT_Price Sample Tbl
Product_FamilyProduct_SubFamilyCountryChannel_CodeChannel_Value
BARMR JEANUS0
BARMR BILLCA
BARMR SMITHUS0
BARMR JEANCA
BARMR JONESUS40
BARMR JONESUS0
BARMR JOHNSONUS0

<tbody>
</tbody>

Strat_Price Sample Tbl, I need to update the Channel_Value with the below table....Thanks
Channel_CodeProduct_FamilyProduct_SubFamilyCountryCurrencyChannel_Value
StoreBARUSUSD0
MarketsBARUSUSD40
MarketsBARMR TOMUSUSD0

<tbody>
</tbody>

This query returned the correct rows to be updated but when I view it, it does not update the Channel_Value columns.....

UPDATE DISTINCTROW Strat_Price_Tbl INNER JOIN Channel_Value_TBL ON (Strat_Price_Tbl.Product_Family = Channel_Value_TBL.PRODUCT_FAMILY) AND (Strat_Price_Tbl.Country = Channel_Value_TBL.COUNTRY) SET Strat_Price_Tbl.Channel_Value = [Channel_Value_TBL].[CHANNEL_VALUE]
WHERE (((Strat_Price_Tbl.Product_Family)="BAR") AND ((Strat_Price_Tbl.Country)="US") AND ((Strat_Price_Tbl.Product_SubFamily) Not Like "MR TOM"));
 
Last edited:
Upvote 0
Can you try again, giving us what was requested in the previous post?
I do not want to see failed query attempts.
I want to see what the underlying tables look like, and what you want to expected results to look like.
 
Upvote 0
Sorry,

I sent you both tables as requested with the Strat_Price Table populated with results sample results loaded....
 
Upvote 0
Here you go,

Strat_Price Sample Tbl
Product_FamilyProduct_SubFamilyCountryCurrencyChannel_CodeChannel_Value
BARMR JEANUSUSDStore
BARMR BILLCAUSDMarkets
BARMR SMITHUSUSDMarkets
BARMR JEANCAUSD
BARMR JONESUSUSD
BARMR JONESUSUSDMarkets
BARMR JOHNSONUSUSDStore

<colgroup><col><col><col span="2"><col><col></colgroup><tbody>
</tbody>

Channel_Value Sample Tbl Update Source Tbl
Product_FamilyProduct_SubFamilyCountryCurrencyChannel_CodeChannel_Value
BARUSUSDStore0
BARUSUSDMarkets40
BARMR TOMUSUSDMarkets 0

<colgroup><col><col><col><col><col><col></colgroup><tbody>
</tbody>


Results from Update
Product_FamilyProduct_SubFamilyCountryCurrencyChannel_CodeChannel_Value
BARMR JEANUSUSDStore 0
BARMR BILLCAUSDMarkets
BARMR SMITHUSUSDMarkets40
BARMR JEANCAUSD
BARMR JONESUSUSDStore 0
BARMR JONESUSUSDStore 0
BARMR JOHNSONUSUSDStore 0

<colgroup><col><col><col span="2"><col><col></colgroup><tbody>
</tbody>

Bare with me, I'm sorta new to this but willing to learn with a bit of help...Mac1206
 
Upvote 0
I don't understand your expected results, i.e.

1. Why is the "MR SMITH" record updated to 40, but not the second "MR JONES" record?

2. Why do some of the Channel Code values change from your first table to your expected output?
 
Upvote 0
Thanks Joe, I will definitely stay within guidelines for sure. Your questions:

1. If you view the update table in the middle, Product_Family, Country, Channel_Code has a Channel_Value = 40, this is my dilemma because Product_Subfamily is blank in the update table but the main Strat_Price Tbl has various Product_Subfamily...You are right, MR JONES met that criteria as well...Typo on my part...

2. It was just a typo on my part creating sample data for you quickly...Thanks
 
Upvote 0

Similar threads

Forum statistics

Threads
1,215,737
Messages
6,126,573
Members
449,318
Latest member
Son Raphon

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