Solved

return result from 2 tables

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
sql calculate reminders 11 73
2 comma seperated list - SQL Server 12 40
Sql Query join multiple table and distinct records 7 30
Query to return total 6 19
by Mark Wills PIVOT is a great facility and solves many an EAV (Entity - Attribute - Value) type transformation where we need the information held as data within a column to become columns in their own right. Now, in some cases that is relatively…
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‚Ķ
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

776 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