Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Help with Conditional Select

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
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    Post subject: Help with Conditional Select
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: 1252
Location: Israel

PostPosted: Tue Aug 19, 2014 5:55 pm    Post subject:
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: 269
Location: Mumbai

PostPosted: Tue Aug 19, 2014 6:58 pm    Post subject:
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    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts CONDITIONAL USING COMP-2 WITH PROBLEMS. JOSUEGENTIL COBOL Programming 7 Wed Nov 08, 2017 11:13 pm
No new posts Conditional highlighting of rows in I... packerm CLIST & REXX 2 Thu Sep 21, 2017 6:50 pm
No new posts Can we limit length in concatenation ... balaji81_k DB2 7 Tue Aug 22, 2017 2:50 am
No new posts Select numeric portion from CHAR data... balaji81_k DB2 6 Sat Aug 19, 2017 1:51 am
No new posts SQL - select data available in index Nileshkul DB2 3 Mon Jun 26, 2017 1:30 am

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us