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

Help with Conditional Select


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

New User


Joined: 19 Aug 2014
Posts: 1
Location: USA

PostPosted: Tue Aug 19, 2014 10:37 am
Reply with quote

Hi All

My first post in this forum and I apologize for starting with a question. I have tried researching on the below query but I could not find/get a solution. Any help is highly appreciated.

1)Generate SQL query that will provide records where account id matches, but if account id does not match, then check for match of cost center id, then check for match of company id

Table name:
Accounts Raw

Columns:
Account ID
Account Cost Center ID
Account Company ID

Table name:
Accounts Target

Columns:
Account ID
Account Cost Center ID
Account Company ID
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Tue Aug 19, 2014 5:55 pm
Reply with quote

Hello and welcome to the Forum.

This sentence does not make much sense (to me):
kaustuv ch wrote:
provide records where account id matches, but if account id does not match, then check for match of cost center id, then check for match of company id

Consider:
1. Rephrasing the question.
2. Providing an example (or two).
3. Providing the query you have written so far.
Back to top
View user's profile Send private message
chandan.inst

Active User


Joined: 03 Nov 2005
Posts: 275
Location: Mumbai

PostPosted: Tue Aug 19, 2014 6:58 pm
Reply with quote

Hi,

if I understand your question correctly check if below query help you

Code:
SELECT
A.Account ID ,
A.Account Cost Center ID ,
A.Account Company ID,
B.Account ID ,
B1.Account Cost Center ID ,
B2.Account Company ID,
FROM Accounts Raw A
LEFT OUTER JOIN
Accounts Target B
ON A.Account ID = B.Account ID
LEFT OUTER JOIN
Accounts Target B1
ON A.Account Cost Center ID= B1.Account Cost Center ID
LEFT OUTER JOIN
Accounts Target B2
ON A.Account Company ID = B2.Account Company ID


in the result value for B, B1 and B2 will have null values if there is no matching row found.

But as marso mentioned your description doesn't make it clear to me as well

I would also suggest what Marso did already

I just thought of giving the query if it suits your requirement

Regards,
Chandan
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 Dynamically pass table name to a sele... DB2 2
No new posts SELECT from data change table DB2 5
No new posts Select two different counts from SQL... DB2 6
No new posts Conditional EATTR in MFS ? IMS DB/DC 0
No new posts Conditional replace values in output ... DFSORT/ICETOOL 3
Search our Forums:

Back to Top