Solved

Sybase Query

Posted on 2012-03-29
2
352 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
  • 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
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…

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now