IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Update table without cursor


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Ron Klop

New User


Joined: 28 Sep 2012
Posts: 28
Location: holland

PostPosted: Wed Oct 11, 2017 1:06 pm
Reply with quote

Hello

The example beneath is somewhat simplified.

I have a table called DIM-month, containing information about months. It contains the next columns.

Month-key
Year
Month-number
Month-name

I also have a table DIM-day. It contains the next columns.
Day-key
Date
Month-key
Weekend-indication
Holiday-indication

Now I added two columns to DIM-month.
Number-weekend-days (this is the aggregation for a specific month of number of records in DIM-day where weekend-indication = Y)
Number-holiday-days (this is the aggregation for a specific month of number of records in DIM-day where holiday-indication = Y)

How do I update these two columns for every row, every month in DIM-month without using a cursor (in for instance a Cobol program)?
So in a single SQL?

Thnx
Ron
Back to top
View user's profile Send private message
RahulG31

Active User


Joined: 20 Dec 2014
Posts: 446
Location: USA

PostPosted: Wed Oct 11, 2017 9:25 pm
Reply with quote

Try this:

Code:
Update DIM-month A
Set Number-weekend-days =
(Select Count(*)
 from DIM-day B
 Where A.Month-key = B.Month-key
  and B.Weekend-indication = 'Y'
 );


Similar query can be run for holiday days.

.
Back to top
View user's profile Send private message
Ron Klop

New User


Joined: 28 Sep 2012
Posts: 28
Location: holland

PostPosted: Fri Oct 13, 2017 12:25 am
Reply with quote

Dank
dit werkt
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2010
Location: USA

PostPosted: Fri Oct 13, 2017 3:26 am
Reply with quote

Ron Klop wrote:
Dank
dit werkt

"Ich weiss nicht was soll es bedeuten..."?
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Load new table with Old unload - DB2 DB2 6
No new posts Pulling a fixed number of records fro... DB2 2
No new posts Multiple table unload using INZUTILB DB2 2
No new posts Check data with Exception Table DB2 0
No new posts Dynamically pass table name to a sele... DB2 2
Search our Forums:

Back to Top