?
Solved

Sybase Query

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

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
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…

765 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