Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups 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: 1232
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 SQL - select data available in index Nileshkul DB2 3 Mon Jun 26, 2017 1:30 am
No new posts Two Selects in a single select query Rohit Umarjikar DB2 1 Fri Nov 04, 2016 8:46 pm
No new posts Select first 2 group data vice_versa DFSORT/ICETOOL 10 Mon Jun 13, 2016 2:21 pm
No new posts Query to select Null row on priority RahulG31 DB2 24 Thu Jan 21, 2016 5:45 pm
No new posts Can I use sort to select sample recor... Steve Ironmonger DFSORT/ICETOOL 3 Tue Nov 10, 2015 10:02 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us