?
Solved

Sybase Query

Posted on 2012-03-29
2
Medium Priority
?
367 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 2000 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

650 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