|
arkiboys
Master Smack Fu Yak Hacker
1433 Posts |
Posted - 2009-11-13 : 09:12:22
|
| There is a table i.e. table1 with fields ID, field1, field2, name, name2fields name and name1 really refer to the same thing.So if a record has the field name2 populated, then I would like to have the same record repeated so that the first record has the field name populated and not the field name2 and the second record has the field name2 populated and not the field name. Everything else for these records will be repeated identically.Thank youexample:create table #table1(ID int identity(1, 1) , field1 varchar(20), field2 varchar(20), name varchar(20), name2 varchar(20))insert into #table1 (field1, field2, name, name2)select 'field1', 'field2', 'peter', 'pete'unionselect 'field11', 'field22', 'jackson', 'jack'unionselect 'field111', 'field222', 'Robert', 'rob'select * from #table1truncate table #table1--RESULTinsert into #table1 (field1, field2, name, name2)select 'field1', 'field2', 'peter', nullunionselect 'field1', 'field2', null, 'pete'unionselect 'field11', 'field22', 'jackson', nullunionselect 'field11', 'field22', null, 'jack'unionselect 'field111', 'field222', 'Robert', nullunionselect 'field111', 'field222', null, 'rob'select * from #table1drop table #table1 |
|