Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Crosstab in SQL

Status
Not open for further replies.
Jun 11, 2008
34
US
I have the following fields
giftkey(numeric)
giftid(char)
giftmkr(char)

I have the following query
select a.giftkey,a.giftid,a.giftmkr
b.giftkey,b.giftid,b.giftmkr


from gifttable a left outer join gifttable b
on a.gifkey=b.gifthrnkey

here is an example of what I get
a.giftkey a.giftid a.giftmkr b.giftkey b.giftid b.giftmkr
00001 11111 null 0002 2222 M
00002 11111 null 0202 3100 b

How would I get a crosstab to display the data like this
a.giftid b.giftid1 b.giftmkr1 b.giftid2 giftmkr2
11111 2222 M 3100 b


Essentially I am grouping by the a.giftid. I am using one ID 11111 as the example
 
If you use SQL Server 2005 or 2008 check PIVOT in BOL

Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top