473,396 Members | 1,702 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

updating stock level from transaction table

I have a 'master' stock list with current stock levels (integer) and
another table that contains transactions (i.e. item#, #items added/
removed, date, user etc). What I need is an update query that runs down
the transaction table and modifies the 'master' stock level
accordingly. I've created an 'update query' and put in the
[master.stock] field. In the 'update to' slot I've got [master]![stock]
+ [transaction]![#items]

Running the query comes up with the message 'updating n records' but it
doesn't actually do it )-;

Any ideas?

Simon

Nov 13 '05 #1
9 5786
<si**********@kingshc.nhs.uk> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
I have a 'master' stock list with current stock levels (integer) and
another table that contains transactions (i.e. item#, #items added/
removed, date, user etc). What I need is an update query that runs down
the transaction table and modifies the 'master' stock level
accordingly. I've created an 'update query' and put in the
[master.stock] field. In the 'update to' slot I've got [master]![stock]
+ [transaction]![#items]

Running the query comes up with the message 'updating n records' but it
doesn't actually do it )-;

Any ideas?

Simon

Post the SQL for the query.
Nov 13 '05 #2
Will do, when my colleague who is designing the db comes back in
tommorrow )-; Thanks for the prompt reply!

Simon

Nov 13 '05 #3
OK, here is the SQL for the update query;

UPDATE Trans INNER JOIN [Items List] ON Trans.[Ref#] = [Items
List].[Ref#] SET [Items List].[In Stock] = [Items List]![In
Stock]+[Trans]![Quantity]
WHERE (((Trans.Updated)=No));

It was created with the 'expression builder' in the 'update to' cell of
the QBE grid so I am assuming the format of the field names etc is
correct (-; The expression builder window just has;

[Items List]![In Stock]+[Trans]![Quantity]

As [In Stock] and [Quantity] are both integers I don't see why I can't
just add them together )-:

Any ideas / suggestions gratefully rec'd.

Simon Harris
P.S.
I was planning on updating the [Updated] field to 'Yes' at the same
time but I thought I'd cross one bridge at a time!

Nov 13 '05 #4
<si**********@kingshc.nhs.uk> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
OK, here is the SQL for the update query;

UPDATE Trans INNER JOIN [Items List] ON Trans.[Ref#] = [Items
List].[Ref#] SET [Items List].[In Stock] = [Items List]![In
Stock]+[Trans]![Quantity]
WHERE (((Trans.Updated)=No));

It was created with the 'expression builder' in the 'update to' cell of
the QBE grid so I am assuming the format of the field names etc is
correct (-; The expression builder window just has;

[Items List]![In Stock]+[Trans]![Quantity]

As [In Stock] and [Quantity] are both integers I don't see why I can't
just add them together )-:

Any ideas / suggestions gratefully rec'd.

Simon Harris
P.S.
I was planning on updating the [Updated] field to 'Yes' at the same
time but I thought I'd cross one bridge at a time!

This query should work if the tables are set up properly. I might expect:
[Items List].Ref# to have a unique index (possibly primary key)
Trans.Ref# would be indexed - probably allowing duplicates
The [In Stock] and [Quantity] fields would be required so that you can't
have null values in there to mess up the addition.

Does this help you to make the query updateable?

Nov 13 '05 #5
"Justin Hoffman" <j@b.com> wrote in message
news:d6**********@nwrdmz03.dmz.ncs.ea.ibs-infra.bt.com...
<si**********@kingshc.nhs.uk> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
OK, here is the SQL for the update query;

UPDATE Trans INNER JOIN [Items List] ON Trans.[Ref#] = [Items
List].[Ref#] SET [Items List].[In Stock] = [Items List]![In
Stock]+[Trans]![Quantity]
WHERE (((Trans.Updated)=No));

It was created with the 'expression builder' in the 'update to' cell of
the QBE grid so I am assuming the format of the field names etc is
correct (-; The expression builder window just has;

[Items List]![In Stock]+[Trans]![Quantity]

As [In Stock] and [Quantity] are both integers I don't see why I can't
just add them together )-:

Any ideas / suggestions gratefully rec'd.

Simon Harris
P.S.
I was planning on updating the [Updated] field to 'Yes' at the same
time but I thought I'd cross one bridge at a time!

This query should work if the tables are set up properly. I might expect:
[Items List].Ref# to have a unique index (possibly primary key)
Trans.Ref# would be indexed - probably allowing duplicates
The [In Stock] and [Quantity] fields would be required so that you can't
have null values in there to mess up the addition.

Does this help you to make the query updateable?


If it's not too late - I would probably be a bit more cautious than this.
Ater all it doesn't leave you much of an audit trail, does it? Is there any
way you could create a temp table from an aggregate query of the Trans
table - i.e. group by Ref# and sum the quantity. You could even add a
separate field in the [Items List] table for the summed trans quantities.
Only as a last step, when you are happy with the results, should you add the
two quantities.

PS You don't mention if this is a procedure to be carried out as a one-off
or will be automated and repeated.



Nov 13 '05 #6
Problem solved - thanks a lot! The fields are defined *exactly* as you
suggested (-: However, because the the data was imported from another
app, the [in stock] field was full of nulls. A quick update to '0' and
we are in business!
Another question now springs to mind (if that's OK with you). How to
filter the form I'm using to update the trans table to only show
records that *aren't* incorporated in the item_list table.
I.e. 'where [updated] = no'

TIA,

Simon

Nov 13 '05 #7
<si**********@kingshc.nhs.uk> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Problem solved - thanks a lot! The fields are defined *exactly* as you
suggested (-: However, because the the data was imported from another
app, the [in stock] field was full of nulls. A quick update to '0' and
we are in business!
Another question now springs to mind (if that's OK with you). How to
filter the form I'm using to update the trans table to only show
records that *aren't* incorporated in the item_list table.
I.e. 'where [updated] = no'

TIA,

Simon


If this is a normal bound form with the updated field displayed (perhaps
with a checkbox control), then can you not simply press the 'filter by form'
button, untick the box, and then apply the filter. Or did you mean
programmatically?
Nov 13 '05 #8
I guess I was thinking of doing it programmatically (i.e. invisibly to
the user). I didn't want to put the 'updated' field on the
'transaction' form where it might be 'unticked' accidentally causing
the amount to be updated more than once on the master table.

Nov 13 '05 #9

<si**********@kingshc.nhs.uk> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
I guess I was thinking of doing it programmatically (i.e. invisibly to
the user). I didn't want to put the 'updated' field on the
'transaction' form where it might be 'unticked' accidentally causing
the amount to be updated more than once on the master table.


You have a number of choices. This one opens the form pre-filtered:

Docmd.OpenForm "MyForm",acNormal,,"[Updated]=0"

But perhaps the form should always show these records, in which case you
would be better off basing the form on a query where you only have the
necessary records. This way, users can't decide to switch the filter off or
alter it to another set of criteria.
I understand the need to stop users doing silly things, but once you get
started on this you may need to make sure that they don't have access to the
database window, can't access standard toolbars and implement user-level
security. I don't know how far down that route you have gone.
Nov 13 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Matthew Roberts | last post by:
To all SQL gurus: I have a Windows Service that uses a single SQL Server table to retrieve items of work. Each thread of the service checks this table for the earliest item of work that is not...
6
by: Hennie de Nooijer | last post by:
Hi, Currently we're a building a metadatadriven datawarehouse in SQL Server 2000. We're investigating the possibility of the updating tables with enormeous number of updates and insert and the...
12
by: Puvendran | last post by:
Hi, We have encountered deadlock on a table which is used to generate sequential numbers for different categories eg typical entries Category Value TRADE_NO ...
6
by: Hasanain F. Esmail | last post by:
Hi all, I sincerly thank you all in advance for your help to solve this problem. I have been trying to find a solution to this problem for sometime now but have failed. I am working on a...
1
by: Michael Thomas | last post by:
Hi everyone I have a database which I use to keep track of stock for the company that I work for. We are a retail chain with 8 locations at present and a head office. I need to keep track of...
3
by: ollyno1uk | last post by:
Hi there I have a table in MySQL database on my web server that contains stock levels amongst other things. twice a day I get emailed an updated stock list in CSV format. What I need is to...
1
by: asmusdk | last post by:
I am working on creating a stock management database for a small company. The company receives the merchandise from a handful of suppliers and stocks it before it is sent to the customers –...
1
by: iceomnia | last post by:
$insertTable = "Table"; $query = "SELECT `gb`.`id` AS `id`, `gb`.`engineId` AS `engineId`, `gb`.`engineUPN` AS `engineUPN`, `gb`.`linkURL` AS `link`, `gb`.`imageURL` AS `image`,...
6
by: Richard Penfold | last post by:
Can someone explain why a field on the many side of a one-to-many relationship, with referential integrity enforced, is not automatically updating? I have 5 tables in my database with the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.