Solved

Sql / Oracle querry help

Posted on 2011-03-15
2
354 Views
Last Modified: 2012-05-11
I am trying to get everyones name and number from the SIDPERS database  that exists in my SQL table with a intRosterID = 4.  When I querry this code below, it gives me everyone in the SIDPERS database, it does not show only the people in my SQL table.  Any ideas on how to tweak this?
SELECT RTRIM(SUBSTRING(GR_ABBR_CODE, 1, 3)) + ' ' + RTRIM(NAME_IND) AS NAME, SSN_SM 
FROM OPENQUERY(SIDPERS, 'SELECT s.GR_ABBR_CODE, s.SSN_SM, p.NAME_IND FROM PERS_SVCMBR_TBL s, PERS_PERSON_TBL p
WHERE s.SSN_SM = p.SSN_SM') WHERE EXISTS (SELECT intMemberID FROM tblMember WHERE intRosterID = 4) ORDER BY SSN_SM

Open in new window

0
Comment
Question by:gfedz
2 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 125 total points
ID: 35137988
>WHERE EXISTS (SELECT intMemberID FROM tblMember WHERE intRosterID = 4) ORDER BY SSN_SM
will only check if there is at least 1 row with that condition, it does not link to the returned rows actually.

the condition on SSN_SM is guessed... you might need to change the condition as needed
SELECT RTRIM(SUBSTRING(GR_ABBR_CODE, 1, 3)) + ' ' + RTRIM(NAME_IND) AS NAME, SSN_SM 
FROM OPENQUERY(SIDPERS, 'SELECT s.GR_ABBR_CODE, s.SSN_SM, p.NAME_IND FROM PERS_SVCMBR_TBL s, PERS_PERSON_TBL p
WHERE s.SSN_SM = p.SSN_SM') sq
WHERE EXISTS (SELECT null FROM tblMember m WHERE m.intRosterID = 4 AND m.intMemberID = sq.SSN_SM ) 
ORDER BY sq.SSN_SM

Open in new window

0
 
LVL 1

Author Closing Comment

by:gfedz
ID: 35138043
That's exactly what I needed.  Thank you for your time.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

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