?
Solved

Join based upon multiple condition

Posted on 2011-10-12
5
Medium Priority
?
255 Views
Last Modified: 2013-11-16
How can i do this in sql

i have table Partner with columns(This table will be master table)

ActivityPartner ID,Sender Partner ID,Receiver Partner ID

then i have another table customer with columns

customer ID,ActivityCustomerKey

i want the logic like



"IF ActivityPartner ID = Customer ID
 then ActivityCustomerKey
else
 IF  Sender Partner ID = Customer ID
then ActivityCustomerKey else
IF Receiver Partner ID= Customer ID
then ActivityCustomerKey
else
ActivityCustomerKey  = 'Unknown'

0
Comment
Question by:sam2929
  • 3
  • 2
5 Comments
 
LVL 11

Expert Comment

by:theartfuldazzler
ID: 36955065
Hi

Use a CASE statement:

PROC SQL;
  Create table p1 as
  select
    CASE WHEN ActivityPartner ID = Customer ID  then ActivityCustomerKey
               WHEN Sender Partner ID = Customer ID then ActivityCustomerKey
Receiver Partner ID= Customer ID
then ActivityCustomerKey
else
ActivityCustomerKey  = 'Unknown'
0
 
LVL 11

Accepted Solution

by:
theartfuldazzler earned 2000 total points
ID: 36955075
Hi

Use a CASE statement:

PROC SQL;
  Create table p1 as
  select
    CASE WHEN ActivityPartner ID = Customer ID  then "Type 1"
               WHEN Sender Partner ID = Customer ID then  "Type 2"
               WHEN Receiver Partner ID= Customer ID then ActivityCustomerKey
               ELSE "Unknown"
   END As ActivityCustomerKey  
0
 

Author Comment

by:sam2929
ID: 36955239
getting error
ACT_CUST_ID is chracter 10
BIC_PARTNER_ID  is chracter 16
ACT_CUST_KEY is integer 8


proc sql;
6             validate
7             select * from stgtcrm.STG_T_TKT_FCT,QSM_DI.ACTIVE_CUST_DIM
8             where CASE WHEN STG_T_TKT_FCT.BIC_PARTNER_ID  = ACTIVE_CUST_DIM.ACT_CUST_ID   then ACTIVE_CUST_DIM.ACT_CUST_KEY
9                                          ELSE 0
10               END As ACTIVE_CUST_DIM.ACT_CUST_KEY;
                     __
                     22
                     76
ERROR 22-322: Syntax error, expecting one of the following: ;, !, !!, &, *, **, +, -, /, <, <=, <>, =, >, >=, ?, AND, BETWEEN,
              CONTAINS, EQ, EQT, EXCEPT, GE, GET, GROUP, GT, GTT, HAVING, IN, INTERSECT, IS, LE, LET, LIKE, LT, LTT, NE, NET, NOT,
              NOTIN, OR, ORDER, OUTER, UNION, ^, ^=, |, ||, ~, ~=.  
2                                                          The SAS System
0
 
LVL 11

Expert Comment

by:theartfuldazzler
ID: 36955409
Hi

Apologies, I'm not sure I understand the question any more.

It is probably easier to give an example of the two tables, and what you want the result to be.

Try this - if it doesn't work - post the examples so we can see what you need...

PROC SQL;
select * from stgtcrm.STG_T_TKT_FCT,QSM_DI.ACTIVE_CUST_DIM
 where STG_T_TKT_FCT.BIC_PARTNER_ID  = ACTIVE_CUST_DIM.ACT_CUST_ID  
   OR
STG_T_TKT_FCT.BIC_SENDER_ID  = ACTIVE_CUST_DIM.ACT_CUST_ID  
  OR
STG_T_TKT_FCT.BIC_RECIEVER_ID  = ACTIVE_CUST_DIM.ACT_CUST_ID   ;
0
 

Author Comment

by:sam2929
ID: 36967592
This will not work
reason is customer id can have one to many relation to partner . what we want is if customer id
is found in ActivityPartner ID then get ActivityCustomerKey  if not then search in Sender Partner ID
if not there then search  Receiver Partner ID
partner
ActivityPartner ID,Sender Partner ID,Receiver Partner ID
101                        101                            101
100                         100                            100

customer will be

customer ID,ActivityCustomerKey
101               1
100                2
103                  3

i want the logic like
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
In this article, I’ll look at how you can use a backup to start a secondary instance for MongoDB.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…
Suggested Courses

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question