?
Solved

Getting stored procedure to return rows that meet condition in one table and match another

Posted on 2003-03-29
9
Medium Priority
?
139 Views
Last Modified: 2010-05-01
table A has rows

ID-name-question
----------
20-fred-no
30-john-yes
25-bert-no

table B has rows

ID2-value-ID.match.table.1
--------------------
114-12132-20
115-22101-25

(a record in table A will either have "yes" in the question column or a matching row in table B)

how can I get a stored procedure to return all the rows in table A that either have "yes" as a value in the question" column or a matching row in table B?

points assigned commensurate with speed of response needed


thanks!
0
Comment
Question by:JCMcNeil
[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
9 Comments
 

Author Comment

by:JCMcNeil
ID: 8230246
by the way, if a row in table a has a "yes" in column 3, it will not match a row in table B
0
 
LVL 14

Expert Comment

by:puranik_p
ID: 8230250
CREATE PROCEDURE RETURNROWS
AS
SELECT A.*
FROM A, B
WHERE
(
  (A.ID = B.IDMATCHTABLE1)
  OR
  (A.QUESTION = 'YES')
)
0
 
LVL 14

Expert Comment

by:puranik_p
ID: 8230256
> points assigned commensurate with speed of response needed

i suppose, you are increasing the points first and then giving the A grade.
right?
;o)
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:JCMcNeil
ID: 8230265
oops, it also has to match 2 values (which is where I ran into trouble) . . .

@ID  and @(another unmentioned column)

this is where it complicated things . . . .
0
 
LVL 14

Expert Comment

by:puranik_p
ID: 8230272
> it also has to match 2 values (which is where I ran into >trouble) . . .
>
>@ID  and @(another unmentioned column)
please explain.
0
 
LVL 14

Expert Comment

by:puranik_p
ID: 8230312
In case of more where clauses, just add them like...
CREATE PROCEDURE RETURNROWS
AS
SELECT A.*
FROM A, B
WHERE
(
 (A.ID = B.IDMATCHTABLE1)
 OR
 (A.QUESTION = 'YES')
)
AND
(
  FIRSTFIELD = 'somevalue'
  AND
  SECONDFIELD = 'anothervalue'
)

I'm leaving now for the weekend :o)

all the best!
0
 
LVL 11

Expert Comment

by:supunr
ID: 8230651
SELECT A.*, B.*
FROM A INNER JOIN B ON A.id = B.id
WHERE (((A.question)="yes"));
0
 
LVL 3

Accepted Solution

by:
ignacioperez earned 1500 total points
ID: 8230729
I believe what you need is something like this:

Select * from
A left join B  
ON (A.ID = B.IDMATCHTABLE1 AND <rest of matching criteria>)
Where
A.question = 'yes'
or
B.ID is not Null

This way, the left join will bring all of the records from A (matching or not with B) then, with the where clause you choose from there those with 'yes' in question and those with actual matches in B.
0
 

Author Comment

by:JCMcNeil
ID: 8230966
Still required a bit of modification but this logic got me there- thanks~!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month12 days, 7 hours left to enroll

777 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