Add two columns in one row

Posted by Venkatesh under Sql Server on 2/17/2011 | Points: 10 | Views : 2069 | Status : [Member] | Replies : 3
Hi,

I am having two tables
One table: campid,primarykey ,surname varchar(),Givenname varchar(50)
second table: Rid int, campid,,surname varchar(),Givenname varchar(50)

how to retrieve these tables in a single row
like
in first table: campid,surname,givenname
1 xyz xyz

in first table: campid,surname,givenname
1 abc abc
2 asdf adf

i want to output like this

campid surname givenname
1 abc abc

1 xyz xyz

2 asdf adf

How to do this

Regards
Venkatesh




Responses

Posted by: PandianS on: 2/17/2011 [Member] [MVP] Silver | Points: 25

Up
0
Down
Hi

SELECT campid,surname,givenname FROM One
UNION ALL
SELECT campid,surname,givenname FROM Two
ORDER BY campid,surname,givenname

Cheers
www.sqlserverbuddy.blogspot.com

Cheers
www.SQLServerbuddy.blogspot.com
iLink Multitech Solutions

Venkatesh, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Venkatesh on: 2/17/2011 [Member] Starter | Points: 25

Up
0
Down
Hi,

Thanks for reply
i will have one more table that is payment table in that registration id is there
like registrationid,payment
234sdf 1500
it will match with second table that registration id available in second table
like campid,surname,givenname,registrationid
1 abcd addf 234sdf
i want payment also
how to do this

Regards
Venkatesh


Venkatesh, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Madhu.b.rokkam on: 2/17/2011 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Hi,

Finally Can you please let us know what all columns you want in the output ?

Thanks and Regards
Madhu

Venkatesh, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response