|
PeterNeo
Constraint Violating Yak Guru
357 Posts |
Posted - 2008-04-04 : 06:56:37
|
| try this,Declare @t Table (FID Bigint, Sname varchar(100), TID1 tinyint, CID1 tinyint, TID2 tinyint, CID2 tinyint, TID3 Tinyint, CID3 tinyint) Insert Into @tSelect 1, 'HT', 3, 10, 2, 4, 2, 5 Union AllSelect 2, 'NT', 2, 11, Null, Null, 3, 5 Union AllSelect 3, 'PT', Null, Null, 3, 5, Null, NullSelect FID, Sname, TID1, CID1, Case When TID1 is not null and CID1 is not null Then 1 End As '1', TID2, CID2, Case When (TID1 is null and CID1 is null) and (TID2 is not null and CID2 is not null) Then 1 When TID2 is not null and CID2 is not null Then 2 End As '2', TID3, CID3, Case When (TID1 is null and CID1 is null) and (TID2 is null and CID2 is null) and (TID3 is not null and CID3 is not null) Then 1 When (TID1 is null and CID1 is null) and (TID2 is not null and CID2 is not null) and (TID3 is not null and CID3 is not null) Then 2 When (TID1 is not null and CID1 is not null) and (TID2 is null and CID2 is null) and (TID3 is not null and CID3 is not null) Then 2 When TID3 is not null and CID3 is not null Then 3 End As '3'From @t |
 |
|