473,583 Members | 4,428 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 5835
<si**********@k ingshc.nhs.uk> wrote in message
news:11******** *************@o 13g2000cwo.goog legroups.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.Update d)=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**********@k ingshc.nhs.uk> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.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.Update d)=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**********@k ingshc.nhs.uk> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.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.Update d)=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**********@k ingshc.nhs.uk> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.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
programmaticall y?
Nov 13 '05 #8
I guess I was thinking of doing it programmaticall y (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**********@k ingshc.nhs.uk> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.com.. .
I guess I was thinking of doing it programmaticall y (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",acNorm al,,"[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
4358
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 already in process, marks that item as in process, then begins to work the item. My concern is whether the threads will begin to step on each other's...
6
5759
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 use of checkpoints (for simple recovery and Backup Log for full recovery). On several website people speak about full transaction log and the pace...
12
9549
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 1456 JOB_NO 267 .....
6
2989
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 project that requires updating data every month. A typical examle is an apartment rental software but could be applied
1
2043
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 quantities of each product for each location. All locations have the same products. The tables are set up as follows: ...
3
3580
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 update the stock quantities in my table with the values from the CSV file. I have managed to successfully upload the CSV file into a different table I...
1
5781
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 – retail outlets. The company works on a concession basis – i.e. the customers do not pay for the delivered goods but sell it on and then take a...
1
1963
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`, `gb`.`retailerTitle` AS `title`, `gb`.`retailerDescription` AS `description`,
6
2401
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 following relationships: Transactions (1-Many) Transaction Details (1-Many) Deliveries Order Codes (1-Many) Transaction Details Order Codes (1-Many) ...
0
7894
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8179
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8323
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7933
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5700
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3816
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3841
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2331
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.