2012-01-19 97 views

回答

0

您可以使用pivot要使用的行,列在這裏是一個有趣的鏈接Refer This

0
declare @T table 
(
    ColumnA varchar(50) 
) 

insert into @T values 
('A1:Data1 A2:Data2 A3:Data3'), 
('A1:Data4 A2:Data5 A3:Data6') 

select substring(ColumnA, Pos.A1+3, Pos.A2-Pos.A1-3) as A1, 
     substring(ColumnA, Pos.A2+3, Pos.A3-Pos.A2-3) as A2, 
     substring(ColumnA, Pos.A3+3, Pos.AX-Pos.A3-3) as A3 
from @T as T 
    cross apply (select charindex('A1:', ColumnA) as A1, 
         charindex('A2:', ColumnA) as A2, 
         charindex('A3:', ColumnA) as A3, 
         len(ColumnA)+1   as AX) as Pos