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 |
|
newuser123
Starting Member
7 Posts |
Posted - 2010-01-05 : 23:54:28
|
| I have table tbl1 as followID code1 code2 code3 code4 code51 A10 D10 A20 f20 u892 B10 J99 R50 k10 p30I want to insert above data in tbl2 which have only 2 columnsID codeOutPut should beID Code1 A10 1 D10 1 A20 1 f20 1 u892 B10 2 J99 2 R50 2 k10 2 p30I don't want to use PIVOT/UNPIVOT concept.Is there any other way to do this? Is it possible with cursor?Plz help me to do this. |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2010-01-06 : 00:24:08
|
| [code]DECLARE @t TABLE (ID INT, code1 VARCHAR(32),code2 VARCHAR(32),code3 VARCHAR(32),code4 VARCHAR(32),code5 VARCHAR(32))INSERT INTO @t SELECT 1, 'A10', 'D10', 'A20', 'f20', 'u89'UNION ALL SELECT 2, 'B10', 'J99', 'R50', 'k10', 'p30'SELECT id,code1 FROM @t UNION ALL SELECT id,code2 FROM @t UNION ALL SELECT id,code3 FROM @t UNION ALL SELECT id,code4 FROM @t UNION ALL SELECT id,code5 FROM @tORDER BY id[/code] |
 |
|
|
|
|
|
|
|