日期:2014-05-18 浏览次数:20457 次
create table T(L1 char(3),L2 varchar(100)) insert T select '001','AAA'+char(10)+'AB'+char(10)+'CD' insert T select '002','BB'+char(10)+'DDD' go declare @sql varchar(8000) set @sql = '' select @sql = @sql + replace(L2,char(10),''' union select '''+L1+''', ''') from (select l1,char(10)+ l2 as l2 from t) a set @sql = stuff(@sql,1,8,'')+'''' exec(@sql) drop table t /* ---- ---- 001 AAA 001 AB 001 CD 002 BB 002 DDD */