Solved

Sybase Query

Posted on 2012-03-29
2
361 Views
Last Modified: 2012-03-29
Table1                                                     Table2

mbr_id                                                      Claim
plan                                                        mbr_id
Sel_type                                                  ps_code
                                                            rc_code)
I need to select every row from Table1 and update Sel_type with a value
of "X" if Table2 has at least one ps_code in ('191', '192', '193') and the plan = 1
If the plan = 2   and rc_code  in ('A', 'B', 'C')    Sel_type = "X"  

Table1                                                                        Table2  
mbr_id                 plan                          Claim           mbr_id      ps_cpde                rc_code
1234                       1                             abc1            4321             200              A
4321                       2                             abc2            1234             200              A
4444                       1                             abc3            4321             191              D
                                                         abc4            4444             193              A
                                                         
                                                         
 result set:
 
 mbr_id                plan                 Sel_type
 
 1234                   1                       null
 4321                   2                      X
 4444                   1                      X
 
 
 
 Please create a Select that will lead to a result as above.
0
Comment
Question by:garyinmiami2003
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 9

Expert Comment

by:rajeevnandanmishra
ID: 37782289
Hi,
Try this.

select a.mbr_id, a.plan, sel_type = (case when b.ps_code is null then null else 'X' end)
from Table1 a left outer join Table2 b
on a.mbr_id = b.mbr_id and ((a.plan = 1 and b.ps_code in ('191', '192', '193') )
                  or a.plan = 2 and rc_code  in ('A', 'B', 'C'))
0
 
LVL 9

Accepted Solution

by:
rajeevnandanmishra earned 500 total points
ID: 37782304
Done some mistake with the code:
Try this one:

select a.mbr_id, a.plan, sel_type = (case when b.ps_code is null then null else 'X' end)
from Table1 a left outer join Table2 b 
on a.mbr_id = b.mbr_id and ((a.plan = 1 and b.ps_code in ('191', '192', '193') ) 
			or (a.plan = 2 and rc_code  in ('A', 'B', 'C')))

Open in new window

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

728 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