473,568 Members | 2,964 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

to trigger or not to trigger

Hello,

I have detail sections in several subforms that are used to fill daily
order data per product. Each row contains textboxes for the weekdays
and a locked textbox (txtTotal) for the week's sum. The week's sum is
also contained in the underlying table and I would like to update it
whenever any of the MonOrder .. SunOrder are changed. I believe the
easiest way to do this is in the backend (SQL Server) using a trigger
(?) - it would save me to go through the many subforms and finding the
event that is triggered when txtTotal.Value changes.

If there is a simple alternative to using a trigger, please tell me.

I think it can be achieved with a simple trigger that updates a row in
one table based on updates of corresponding fields of same row. Its a
"week total" field that sums up values of 7 singular "day" fields. Here
is what I have come up with using the TSQL documentation.

CREATE TRIGGER trigger_stocksu m ON tblStock FOR UPDATE
AS
IF UPDATE(MonOrder ) OR UPDATE(TueOrder ) OR UPDATE(WedOrder ) OR
UPDATE(ThursOrd er) OR UPDATE(FriOrder ) OR UPDATE(SatOrder ) OR
UPDATE(SunOrder )
SET TotalOrder =
(MonOrder+TueOr der+WedOrder+Th ursOrder+FriOrd er+SatOrder+Sun Order)

all these fields (including TotalOrder) are contained in tblStock, I
get a syntax error
Server: Msg 170, Level 15, State 1, Procedure trigger_stocksu m, Line 4
Line 4: Incorrect syntax near '='.

Can somebody please help me?

Nov 13 '05 #1
3 2086
Hi group,

after some research on
http://groups.google.ie/group/comp.d...qlserver?hl=en

I have opted for changing the field to a computed field.
this is the new table
(snipped):

<snip>

ALTER TABLE dbo.tblStock
DROP CONSTRAINT DF_tblStock_Sun Order
GO
CREATE TABLE dbo.Tmp_tblStoc k
(
YearWeek int NOT NULL,
ProductCode nvarchar(50) NOT NULL,
StockonHand int NULL,
StockonOrder int NULL,
TotalOrder AS
MonOrder+TueOrd er+WedOrder+Thu rsOrder+FriOrde r+SatOrder+SunO rder,

MonOrder int NULL,
TueOrder int NULL,
WedOrder int NULL,
ThursOrder int NULL,
FriOrder int NULL,
SatOrder int NULL,
SunOrder int NULL,
Dummy1 nvarchar(50

) NULL
) ON [PRIMARY]
GO
<snip>
the reason I can not normalize the table so easily (as much as I would
like to) is that it is currenty used in at least 22 queries and 11
forms in the frontend. It is used during Stock upload (importing a raw
table which is normalized in the same way) and stock reporting and in
all cases the separate storage of days in week fields seems to be quite
intuitive and performance appears to work quite well, so I am not too
bothered about changing it any time soon. Apart from that the data of
this table is not used anywhere else so this is more like a view
anyway. I am quite glad though that I did not create a trigger as it
would not work on row level anyway and would decrease performance.

hth
axel

Nov 13 '05 #2
On 2 Jun 2005 04:37:44 -0700, "Axel" <ax***@gofree.i ndigo.ie> wrote:
Hello,

I have detail sections in several subforms that are used to fill daily
order data per product. Each row contains textboxes for the weekdays
and a locked textbox (txtTotal) for the week's sum. The week's sum is
also contained in the underlying table and I would like to update it
whenever any of the MonOrder .. SunOrder are changed. I believe the
easiest way to do this is in the backend (SQL Server) using a trigger
(?) - it would save me to go through the many subforms and finding the
event that is triggered when txtTotal.Value changes.

If there is a simple alternative to using a trigger, please tell me.

I think it can be achieved with a simple trigger that updates a row in
one table based on updates of corresponding fields of same row. Its a
"week total" field that sums up values of 7 singular "day" fields. Here
is what I have come up with using the TSQL documentation.

CREATE TRIGGER trigger_stocksu m ON tblStock FOR UPDATE
AS
IF UPDATE(MonOrder ) OR UPDATE(TueOrder ) OR UPDATE(WedOrder ) OR
UPDATE(ThursOr der) OR UPDATE(FriOrder ) OR UPDATE(SatOrder ) OR
UPDATE(SunOrde r)
SET TotalOrder =
(MonOrder+TueO rder+WedOrder+T hursOrder+FriOr der+SatOrder+Su nOrder)

all these fields (including TotalOrder) are contained in tblStock, I
get a syntax error
Server: Msg 170, Level 15, State 1, Procedure trigger_stocksu m, Line 4
Line 4: Incorrect syntax near '='.

Can somebody please help me?

Hi
Why store the sum in a table at all? Normal practice would be to
calculate it in a view or query.
If you are using forms, the afterupdate events can be used in place of
triggers.
David
Nov 13 '05 #3
> Why store the sum in a table at all? Normal practice would be to calculate it in a view or query.

Hi David,

true. The only reason why I did it this way was that I did not have
time to go through the frontend Access database (my colleague had
written most of this) to find all the places where the field was used.
But since it now is a calculated field it does not even take any
storage space, so I think thats a pretty neat solution.

I did not create a view because I have never done that before - and I
already had 'wasted' over an hour to investigate triggers and their
syntax.

In hindsight I could probably also have created a pass through query in
Access to replace the original table - which would have lead to the
same goal. For me it was important not to break the existing code or to
have the customer relink any tables.

regards,
Axel

PS: I am using google's web interface to create this message any idea
how I can hide my email addy? According to this page
"The group you are posting to is a Usenet group. Messages posted to
this group will make your email visible to anyone on the Internet."
To rephrase the question, does anybody know how I can add this group to
my thunderbird newsgroups?

Nov 13 '05 #4

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

Similar topics

6
7128
by: Mary | last post by:
We are developing a DB2 V7 z/OS application which uses a "trigger" table containing numerous triggers - each of which is activated by an UPDATE to a different column of this "trigger" table. When the triggers are fired, various other operations are performed on other tables in the database. The triggers are not created on these other...
0
7131
by: Dave Sisk | last post by:
I've created a system or external trigger on an AS/400 file a.k.a DB2 table. (Note this is an external trigger defined with the ADDPFTRG CL command, not a SQL trigger defined with the CREATE TRIGGER statement.) I've also defined a SQL stored proc, and the trigger is set to call this SP. I've posted the simplified source below. I can...
0
2461
by: JohnO | last post by:
Thanks to Serge and MarkB for recent tips and suggestions. Ive rolled together a few stored procedures to assist with creating audit triggers automagically. Hope someone finds this as useful as I've found it educational. Note: - I build this for use in a JDEdwards OneWorld environment. I'm not sure how generic others find it but it...
9
9299
by: Ots | last post by:
I'm using SQL 2000, which is integrated with a VB.NET 2003 app. I have an Audit trigger that logs changes to tables. I want to apply this trigger to many different tables. It's the same trigger, with the exception of the table name. I could manually change the table name in the trigger and create it, over and over, but I'd like to automate...
11
7853
by: tracy | last post by:
Hi, I really need help. I run this script and error message appeal as below: drop trigger log_errors_trig; drop trigger log_errors_trig ERROR at line 1: ORA04080: trigger 'LOG_ERRORS-TRIG' does not exist drop table log_errors_tab;
0
7693
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
7604
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7916
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. ...
1
7660
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...
1
5498
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
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3651
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...
1
2101
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
1
1207
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.