--Convert line to string select Stuff ([select top], ' + QQ from DL_QQ where uiid=1 order by Tim Desc FOR XML Path (') '), 1, 1, ')--======= ======================================--Description: Converting a string to a table/* Example: SELECT * FROM [F_split] (' spu0987*5//spu0988*5/ Spu0989*5 ', '/')--convert the table to a string 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
sql2008 converts rows to strings, converts strings to rows