If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > stored procedure to create

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-24-09, 03:05
laknar laknar is offline
Registered User
 
Join Date: Jul 2008
Posts: 80
stored procedure to create

Code:
--------------------------------------------------
-- Create Table TEST1
--------------------------------------------------
Create table TEST1 (
    JOB                            VARCHAR(50)                     ,
    KLI                            VARCHAR(50)                     ,
    VDATE                          DATE                            ,
    STAT                           VARCHAR(50)                     ,
    FTYPE                          VARCHAR(50)                     ) 
in USERSPACE1   ;

Insert into TEST1 values('D', 'HH', '2009-03-24', 'W', 'I');
Insert into TEST1 values('G', 'HH', '2009-03-24', 'W', 'D');
Insert into TEST1 values('G', 'HH', '2009-03-24', 'W', 'F');
Insert into TEST1 values('G', 'HH', '2009-03-24', 'W', 'G');
Insert into TEST1 values('N', 'HH', '2009-03-24', 'W', 'D');
Insert into TEST1 values('N', 'HH', '2009-03-24', 'W', 'F');
Insert into TEST1 values('N', 'HH', '2009-03-24', 'W', 'G');
Insert into TEST1 values('R', 'HH', '2009-03-24', 'W', 'L');
Insert into TEST1 values('S', 'HH', '2009-03-24', 'W', 'A');
Insert into TEST1 values('T', 'HH', '2009-03-24', 'W', 'D');
Insert into TEST1 values('T', 'HH', '2009-03-24', 'W', 'F');
Insert into TEST1 values('T', 'HH', '2009-03-24', 'W', 'G');
If STAT='S' Where FTYPE='A' AND JOB='S' Then Update STAT='R' WHere JOB='T';

IF STAT ='S' WHERE JOB='T' then Update STATS ='R' WHere JOB='N' for the corresponding FTYPE;

for the job 'N' and FTYPE ='F' is dependent on both FTYPE 'F' and 'G" in JOB='T' i.e(both the JOB 'T' STAT should be 'S' before updating 'R' WHere JOB='N' for the corresponding FTYPE='F'

IF STAT ='S' WHERE JOB='T' and FTYPE='D' then Update STATS ='R' WHere JOB='N' for the corresponding FTYPE

For JOB 'G'
IF STAT ='S' WHERE JOB='N' then Update STATS ='R' WHere JOB='G' for the corresponding FTYPES;

How can i write the above in stored procedure.
Reply With Quote
  #2 (permalink)  
Old 03-24-09, 08:42
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
Turn each of your statements into proper SQL update statements. Then look up the CREATE PROCEDURE statement to see how to put those update statements into it.

Andy
Reply With Quote
  #3 (permalink)  
Old 03-24-09, 15:18
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
1)
Quote:
If STAT='S' Where FTYPE='A' AND JOB='S' Then Update STAT='R' WHere JOB='T';
I couldn't understand this.
Because If JOB='S', then the row sould not satidfy the condition "WHere JOB='T'".

Or, do you want if there is a row with STAT='S' Where FTYPE='A' AND JOB='S', then update all rows WHere JOB='T'?

2) You had better to include the data which satisfy your requirements.
For example, rows with STAT='S',
Then show me(us?) which rows to update for each conditions.

3) What platform and version do you use?
If you are using DB2 for LUW, you can specify multiple rows in a VALUES statement. Like this:
Code:
Insert into TEST1 values
 ('D', 'HH', '2009-03-24', 'W', 'I')
,('G', 'HH', '2009-03-24', 'W', 'D')
,('G', 'HH', '2009-03-24', 'W', 'F')
,('G', 'HH', '2009-03-24', 'W', 'G')
,('N', 'HH', '2009-03-24', 'W', 'D')
,('N', 'HH', '2009-03-24', 'W', 'F')
,('N', 'HH', '2009-03-24', 'W', 'G')
,('R', 'HH', '2009-03-24', 'W', 'L')
,('S', 'HH', '2009-03-24', 'W', 'A')
,('T', 'HH', '2009-03-24', 'W', 'D')
,('T', 'HH', '2009-03-24', 'W', 'F')
,('T', 'HH', '2009-03-24', 'W', 'G')
;
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On