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 |
|
shiyam198
Yak Posting Veteran
94 Posts |
Posted - 2011-05-30 : 14:42:05
|
| Hi,I have a table called temp which has two colummns.Account No | Data1 | Apple1 | Orange1 | Pear2 | Apple2 | PearI have another table "RealData" that has AccountNo | Fruit01 | Fruit02 | Fruit03AccountNo is unique here.I need to get the data from "temp" and load it to "ReadData".for e.g. "RealData" will become:AccountNo | Fruit01 | Fruit02 | Fruit031 | Apple | Orange | PearHow can I do this? I appreciate your time.Regards,Shiyam |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2011-05-30 : 15:54:47
|
| You need to UNPIVOT the dataDECLARE @Table Table (AccountNo int ,Fruit01 varchar(10),Fruit02 varchar(10))INSERT INTO @TableSELECT 1223,'banana','apple' SELECT AccountNO,FruitFROM (select accountNo,Fruit01,Fruit02 from @table ) pUNPIVOT ( Fruit For Fruits in ([Fruit01],[Fruit02]) ) upvtJimEveryday I learn something that somebody else already knew |
 |
|
|
|
|
|