Solved

return result from 2 tables

Posted on 2009-07-15
3
171 Views
Last Modified: 2012-05-07
I want to return 2 columns from stored procedure:  FullName and UserSSN.
I have got 2 tables that contain different types of users.
Both tables have got the columns: FullName, UserName and PayerId.
The parameter I send in is @PayerId.
I want to return from both tables FullName and UserSSN.
How would i do that?
0
Comment
Question by:johnkainn
3 Comments
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 100 total points
ID: 24860392
SELECT FullName, UserSSN
FROM Table1
WHERE PayerID = @PayerID
UNION
SELECT FullName, UserSSN
FROM Table2
WHERE PayerID = @PayerID
0
 
LVL 60

Assisted Solution

by:chapmandew
chapmandew earned 100 total points
ID: 24860403
select fullname, userssn
from table1
where payerid =  @payerid
union all
select fullname, userssn
from table2
where payerid =  @payerid
0
 
LVL 17

Assisted Solution

by:pssandhu
pssandhu earned 50 total points
ID: 24860426
CREATE PROCDURE sp_GetPayerInfo ( @PayeriD INT)
AS
BEGIN

Select a.FullName TableOneName, a.UserSSN as TableOneSSN, b.FullName TableTwoName, b.UserSSN as TableTwoSSN
From TableA a inner join TableB b
           ON a.PayerID = b.PayerID
Where  a.PayerID = @payerid
END
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Stored Procedure error 45 48
MessageHandler Database in SQL way too large 4 42
Stored procedure 4 32
SSRS report parameters set after publishing to report manager 1 50
This article will describe one method to parse a delimited string into a table of data.   Why would I do that you ask?  Let's say that you need to pass multiple parameters into a stored procedure to search for.  For our sake, we'll say that we wa…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
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…

863 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

28 Experts available now in Live!

Get 1:1 Help Now