Solved

Sql / Oracle querry help

Posted on 2011-03-15
2
355 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Excel conversion issue with Sql server 14 50
SQL Query 34 82
SYNTAX PROBLEM -- adding another column into the stored procedure output 30 32
sql query questions 2 24
Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
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…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

896 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

16 Experts available now in Live!

Get 1:1 Help Now