Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
SangeethaMathew
Starting Member
1 Post |
Posted - 2010-05-22 : 23:20:33
|
| I have got a table that stores user's addresses. One user can have 3 different addresses. Each address has a unique number. "Select address from USER_ADDRESS where addrNum=300 or addrNum=301 or addrNum=302" would return three rows of addresses for a single user who has got address numbers 300,301 and 302 as follows:address-------addr1addr2addr3Is there any way to combine these results into a single row:column1 column2 column3------------------------------------------------------addr1 addr2 addr3Thanks and Regards,Sangeetha |
|
|
sodeep
Master Smack Fu Yak Hacker
7174 Posts |
Posted - 2010-05-23 : 12:22:19
|
| Yes with PIVOT or Cross-tab method. See booksonline for PIVOT function. |
 |
|
|
AndrewMurphy
Master Smack Fu Yak Hacker
2916 Posts |
Posted - 2010-05-24 : 07:33:57
|
| select a.address1, b.address1, c.address1from mytable aleft join mytable b on b.cust = a.cust and b.rectype = 302left join mytable c on c.cust = a.cust and c.rectype = 303where a.rectype = 301all predicated on there being 1 "301" type record per customer to drive the rpcoess. |
 |
|
|
|
|
|