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

DB2 sql query to fetch from two tables


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

New User


Joined: 29 Nov 2006
Posts: 19
Location: amsterdam

PostPosted: Thu Jan 18, 2007 2:03 am
Reply with quote

for the rows that come from the table without timestamp
i would like have spaces in the timestamp
OR
Just curious, is it possible that I have some hardcoded values in them, like 1701200600000000 .... icon_sad.gif guess it would not be possible
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Thu Jan 18, 2007 2:08 am
Reply with quote

Hi Sandip,

One solution would be to declare 2 cursors with the ordered-by-date - one for each table.

Then fetch rows from the cursors the same way you would process 2 flat files that you wanted to match.
Back to top
View user's profile Send private message
DavidatK

Active Member


Joined: 22 Nov 2005
Posts: 700
Location: Troy, Michigan USA

PostPosted: Thu Jan 18, 2007 2:35 am
Reply with quote

Like This?


Code:

SELECT *                   
  FROM SESSION.TMUTATION   
;                           

   +---------------------------------------------------+
   | BEDRAG  | VALUEDATUM |         TIMESTAMP          |
   +---------------------------------------------------+
 1_|   300   | 2006-09-27 | 2006-09-27-14.02.26.472344 |
 2_|   500   | 2006-12-27 | 2006-12-27-16.32.41.678235 |
 3_|   100   | 2007-01-01 | 2007-01-01-09.14.11.924119 |
   +---------------------------------------------------+
                                                       

SELECT *                 
   FROM SESSION.TSUBTOT   
 ;                       

  +----------------------+
  | BEDRAG  | VALUE_DATE |
  +----------------------+
1_|  1000   | 2006-12-12 |
2_|   200   | 2006-11-10 |
3_|   150   | 2007-01-02 |
  +----------------------+

SELECT VALUEDATUM    AS DT,         
       BEDRAG        AS AMT,         
       TIMESTAMP     AS TS           
  FROM SESSION.TMUTATION             
UNION ALL                           
SELECT VALUE_DATE    AS DT,         
       BEDRAG        AS AMT,         
       CAST(NULL AS CHAR(26)) AS TS 
  FROM SESSION.TSUBTOT               
 ORDER BY DT                         
;                                   

    +---------------------------------------------------+
    |     DT     |   AMT   |             TS             |
    +---------------------------------------------------+
  1_| 2006-09-27 |   300   | 2006-09-27-14.02.26.472344 |
  2_| 2006-11-10 |   200   | ?                          |
  3_| 2006-12-12 |  1000   | ?                          |
  4_| 2006-12-27 |   500   | 2006-12-27-16.32.41.678235 |
  5_| 2007-01-01 |   100   | 2007-01-01-09.14.11.924119 |
  6_| 2007-01-02 |   150   | ?                          |
    +---------------------------------------------------+

SELECT VALUEDATUM    AS DT,     
       BEDRAG        AS AMT,     
       TIMESTAMP     AS TS       
  FROM SESSION.TMUTATION         
UNION ALL                       
SELECT VALUE_DATE    AS DT,     
       BEDRAG        AS AMT,     
       '1701200600000000'       
  FROM SESSION.TSUBTOT           
 ORDER BY DT                     
;                               

    +---------------------------------------------------+
    |     DT     |   AMT   |             TS             |
    +---------------------------------------------------+
  1_| 2006-09-27 |   300   | 2006-09-27-14.02.26.472344 |
  2_| 2006-11-10 |   200   | 1701200600000000           |
  3_| 2006-12-12 |  1000   | 1701200600000000           |
  4_| 2006-12-27 |   500   | 2006-12-27-16.32.41.678235 |
  5_| 2007-01-01 |   100   | 2007-01-01-09.14.11.924119 |
  6_| 2007-01-02 |   150   | 1701200600000000           |
    +---------------------------------------------------+
                                                       
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 RC query -Time column CA Products 3
No new posts Dynamically pass table name to a sele... DB2 2
No new posts Fetch data from programs execute (dat... DB2 3
No new posts Query on edit primary command CLIST & REXX 5
No new posts Query on edit primary command CLIST & REXX 1
Search our Forums:

Back to Top