473,387 Members | 1,757 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,387 software developers and data experts.

help request

Hi to all NG

Sorry for my bad English,
I write a peace of code in trigger. more in detail I write a select, in
order to check th primary key in another table and if the record is present
I issue an update in other case I issue an insert.

I have got a book that tolking about create trigger, with some examples but
I can't find the good information. So I don't understand how to declare a
variable in the trigger in order to use a select 1 into :variable from
table1 and so on

Someone may I indicate some book to read or some example to watch or other
type of suggest ?
best thks in advance
Sergio
Nov 12 '05 #1
3 1401
Again me.

in order to explain better I try this examples but it does not work.
Create Trigger ITSO4710/InsertOrderHeaderTotal

After Insert on ITSO4710/ORDER_DETAIL

Referencing NEW_TABLE as NewDetail

For Each Statement

Mode DB2SQL

Set Option DbgView = *SOURCE

BEGIN ATOMIC

Declare SumTotal Decimal(7, 0);

select coalesce(sum(NewDetail.OrderDtl_Total), 0)

into SumTotal

from NewDetail;

update Order_Header

set Order_Total = Order_Total + SumTotal ;

END;

Where is the problem ????

"eap90210" <ea******@yahoo.it> ha scritto nel messaggio news:dh**********@stargate1.inet.it...
Hi to all NG

Sorry for my bad English,
I write a peace of code in trigger. more in detail I write a select, in
order to check th primary key in another table and if the record is present
I issue an update in other case I issue an insert.

I have got a book that tolking about create trigger, with some examples but
I can't find the good information. So I don't understand how to declare a
variable in the trigger in order to use a select 1 into :variable from
table1 and so on

Someone may I indicate some book to read or some example to watch or other
type of suggest ?


best thks in advance
Sergio

Nov 12 '05 #2
eap90210 wrote:
Again me.

in order to explain better I try this examples but it does not work.

Create Trigger ITSO4710/InsertOrderHeaderTotal

After Insert on ITSO4710/ORDER_DETAIL

Referencing NEW_TABLE as NewDetail

For Each Statement

Mode DB2SQL

Set Option DbgView = *SOURCE

BEGIN ATOMIC

Declare SumTotal Decimal(7, 0);

select coalesce(sum(NewDetail.OrderDtl_Total), 0)

into SumTotal

from NewDetail;

update Order_Header

set Order_Total = Order_Total + SumTotal ;

END;

Where is the problem ????

"eap90210" <ea******@yahoo.it <mailto:ea******@yahoo.it>> ha scritto nel
messaggio news:dh**********@stargate1.inet.it...
> Hi to all NG
>
> Sorry for my bad English,
> I write a peace of code in trigger. more in detail I write a select, in
> order to check th primary key in another table and if the record is

present
> I issue an update in other case I issue an insert.
>
> I have got a book that tolking about create trigger, with some

examples but
> I can't find the good information. So I don't understand how to

declare a
> variable in the trigger in order to use a select 1 into :variable from
> table1 and so on
>
> Someone may I indicate some book to read or some example to watch or

other
> type of suggest ?

In triggers DB2 for LUW supports the SET statement, but not SELECT INTO
or VALUES INTO.
Either way, please take a look at the MERGE statement. It is meant to
solve "if not exist INSERT otherwise UPDATE" problems.

Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #3
thanks
Cheers
Sergio
"Serge Rielau" <sr*****@ca.ibm.com> ha scritto nel messaggio
news:3p************@individual.net...
eap90210 wrote:
Again me.
in order to explain better I try this examples but it does not work.

Create Trigger ITSO4710/InsertOrderHeaderTotal

After Insert on ITSO4710/ORDER_DETAIL

Referencing NEW_TABLE as NewDetail

For Each Statement

Mode DB2SQL

Set Option DbgView = *SOURCE

BEGIN ATOMIC

Declare SumTotal Decimal(7, 0);

select coalesce(sum(NewDetail.OrderDtl_Total), 0)

into SumTotal

from NewDetail;

update Order_Header

set Order_Total = Order_Total + SumTotal ;

END;

Where is the problem ????

"eap90210" <ea******@yahoo.it <mailto:ea******@yahoo.it>> ha scritto nel
messaggio news:dh**********@stargate1.inet.it...
> Hi to all NG
>
> Sorry for my bad English,
> I write a peace of code in trigger. more in detail I write a select,

in
> order to check th primary key in another table and if the record is

present
> I issue an update in other case I issue an insert.
>
> I have got a book that tolking about create trigger, with some

examples but
> I can't find the good information. So I don't understand how to

declare a
> variable in the trigger in order to use a select 1 into :variable from
> table1 and so on
>
> Someone may I indicate some book to read or some example to watch or

other
> type of suggest ?

In triggers DB2 for LUW supports the SET statement, but not SELECT INTO or
VALUES INTO.
Either way, please take a look at the MERGE statement. It is meant to
solve "if not exist INSERT otherwise UPDATE" problems.

Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab

Nov 12 '05 #4

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

Similar topics

0
by: Pat Patterson | last post by:
I'm having serious issues with a page I'm developing. I just need some simple help, and was hoping someone might be able to help me out in here. I have a form, that consists of 3 pages of...
9
by: Peter | last post by:
My problem is the last bit of coding below, the like statement does not work. what I have is a product options field and in it is stored characters i.e. "avcy" etc what the query does is...
4
by: DOTNET | last post by:
Hi, Anybody help me regarding this error: I am assigning the values to the session variables when the button is clicked and passing these session variables to the next page and when I am...
6
by: James Radke | last post by:
Hello, I have a multithreaded windows NT service application (vb.net 2003) that I am working on (my first one), which reads a message queue and creates multiple threads to perform the processing...
4
by: Michael Kujawa | last post by:
I am using the following to create an SQL statement using the names and values from request.form. The loop goes through each item in request.form The issue comes in having an additional "and" at...
10
by: 60325 | last post by:
This is the page where I collect the data in drop-down boxes with values of 1-10 and send it to a submitted page to do calculations. Example: Employee1 TeamScore(1-10) Employee2 ...
10
by: pmarisole | last post by:
This is the first page...... <select size="1" name="Q1_<%=i%>" onChange="calc(<%=i%>)"> <option selected value="<% =rsScores("Q1") <option value="1">1</option> <option value="2">2</option>...
6
by: AppleBag | last post by:
I'm having the worst time trying to login to myspace through code. Can someone tell me how to do this? Please try it yourself before replying, only because I have asked this a couple of times in...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
3
by: ibeehbk | last post by:
Hi. I have a form made in xhtml. I test via vbscript to make sure none of the fields are empty and properly formatted (ie email). All the regular fields work. However, I have two drop down menus...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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,...

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.