--将行转为字符串 select stuff((select top 20 ','+ QQ from dl_QQ where uiid=1 order by tim desc for xml path('')),1,1,'') -- ============================================= -- Description: 将字符串转为表格 /* 例:select * from [f_split]('spu0987*5//spu0988*5/spu0989*5', '/') --将表格转为字符串 DECLARE @S nVARCHAR(max) SELECT @S=ISNULL(@S+',','')+[col] FROM [f_split]('spu0987*5//spu0988*5/spu0989*5', '/') PRINT @S */ -- ============================================= create function [dbo].[strToTab](@c varchar(max),@split varchar(2)) returns @t table(col nvarchar(255)) as begin while(charindex(@split,@c)<>0) begin insert @t(col) values (substring(@c,1,charindex(@split,@c)-1)) set @c = stuff(@c,1,charindex(@split,@c),'') end insert @t(col) values (@c) return end