Solved

return result from 2 tables

Posted on 2009-07-15
3
175 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

Independent Software Vendors: 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!

Question has a verified solution.

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

Suggested Solutions

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
I've encountered valid database schemas that do not have a primary key.  For example, I use LogParser from Microsoft to push IIS logs into a SQL database table for processing and analysis.  However, occasionally due to user error or a scheduled task…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

726 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