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

Compound Query


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

New User


Joined: 24 Jun 2008
Posts: 4
Location: Rochester

PostPosted: Sat Jan 21, 2012 12:58 am
Reply with quote

Appreciate if someone could look at this & provide an UPDATE query

Table A - IPMA

BUSSINESS_ENTITY (pk)
PRICE_TYPE (pk)
PRICE_ID (pk)
DATE_TIME
USERID
BUSN_ENT
ITEM_TYPE
ITEM_ID
TYPE
SUPPLIER
STATUS
STATUS_DATETIME

Table B - IPDT

BUSINESS_ENTITY (pk)
PRICE_TYPE (pk)
PRICE_ID (pk)
BUS_ENT (pk)
TYPE (pk)
CODE
EFF_START
DATETIME
USERID
EFF_STOP
ENTER_DATE
PRICE
STATUS
STATUS_DATETIME
REFERENCE


The ITEM_ID is ONE-to-MANY, with respect to EFF_START & EFF_STOP (from table: IPDT)

The total rows on table: IPDT = 980,000
With the following query, I got: 2500 rows,

Now, I need a SINGLE query, to update EFF_DATE of 2500 rows, on table: IPDT. (I tried with using EXISTS, IN on UPDATE statement but could not yet achieve desired result).

SELECT A.ITEM_ID,
B.EFF_START,
B.EFF_STOP
FROM IPMA A,
IPDT B
WHERE A.BUSINESS_ENTITY = B.BUSINESS_ENTITY
AND A.PRICE_TYPE = B.PRICE_TYPE
AND A.PRICE_ID = B.PRICE_ID
AND B.EFF_START =
(SELECT MAX(C.EFF_START)
FROM IPDT C
WHERE C.BUSINESS_ENTITY = B.BUSINESS_ENTITY
AND C.PRICE_TYPE = B.PRICE_TYPE
AND C.PRICE_ID = B.PRICE_ID
)
AND B.EFF_STOP BETWEEN '2011-06-30'
AND '9999-06-30'
AND B.EFF_STOP <> '9999-06-30');
Code:
Back to top
View user's profile Send private message
Akatsukami

Global Moderator


Joined: 03 Oct 2009
Posts: 1787
Location: Bloomington, IL

PostPosted: Sat Jan 21, 2012 1:02 am
Reply with quote

You should probably begin by defining a column named EFF_DATE on IPDT.
Back to top
View user's profile Send private message
Cruise

New User


Joined: 24 Jun 2008
Posts: 4
Location: Rochester

PostPosted: Sat Jan 21, 2012 1:16 am
Reply with quote

Akatsukami - Thanks for the quick reply.

Can you you elaborate what you mean - if you are saying to ADD another physical column to the table IPDT, that is not possible.

This query is updating, around 89000 rows - but expected to update 2500 rows only.

UPDATE IPDT
SET EFF_STOP = '9999-06-30'
WHERE EFF_STOP IN
(SELECT B.EFF_STOP
FROM IPMA A,
IPDT B
WHERE A.BUSINESS_ENTITY = B.BUSINESS_ENTITY
AND A.PRICE_TYPE = B.PRICE_TYPE
AND A.PRICE_ID = B.PRICE_ID
AND B.EFF_START =
(SELECT MAX(C.EFF_START)
FROM IPDT C
WHERE C.BUSINESS_ENTITY = B.BUSINESS_ENTITY
AND C.PRICE_TYPE = B.PRICE_TYPE
AND C.PRICE_ID = B.PRICE_ID
)
AND B.EFF_STOP BETWEEN '2011-06-30'
AND '9999-06-30'
AND B.EFF_STOP <> '9999-06-30');
Back to top
View user's profile Send private message
Akatsukami

Global Moderator


Joined: 03 Oct 2009
Posts: 1787
Location: Bloomington, IL

PostPosted: Sat Jan 21, 2012 1:58 am
Reply with quote

Note that as there is no column named EFF_DATE, you can't update it. Is EFF_DATE a typo for EFF_START, EFF_STOP, or ENTER_DATE, or do you mean "I want to set a certain range of effective dates, i.e., set EFF_START to this value, and EFF_STOP to that value"?
Back to top
View user's profile Send private message
Cruise

New User


Joined: 24 Jun 2008
Posts: 4
Location: Rochester

PostPosted: Sat Jan 21, 2012 2:23 am
Reply with quote

A certain range - MAX(EFF_START) and EFF_STOP (BETWEEN '2011-06-30' AND '9999-06-30')

And, SET EFF_STOP to: '9999-06-30, which are not equal to '9999-06-30'.
Back to top
View user's profile Send private message
Cruise

New User


Joined: 24 Jun 2008
Posts: 4
Location: Rochester

PostPosted: Sat Jan 21, 2012 2:25 am
Reply with quote

Yes, EFF_DATE is a TYPO - Please read it as, EFF_STOP of 2500 rows...
Back to top
View user's profile Send private message
View previous topic : : View next topic  
Post new topic   Reply to topic All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts DB2 Query to get the count of Unique ... DB2 2
No new posts Need help with ADABAS query (COBOL-AD... All Other Mainframe Topics 1
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 Query on edit primary command CLIST & REXX 5
Search our Forums:


Back to Top