Split a field to become a line

xiaoxiao2021-03-06  38

- Generate test data ------------ with ',' is separator Select * Into #efrom (select '001' [id], 'aaa, bbb, ccc' [strall] union allselect '002', 'bbb, ccc') A ---------------------

Declare @s intDeclare @P varchar (50) - Delivery set @ p = ','

SELECT @ s = max (lin (strall)) from # e - select @s - Find the length of the length of this field

Set rowcount @sselect identity (int, 1, 1) AS ID INTO #T from syscolumns a, syscolumns b - select * from #t - Create a row of table set rowcount 0-- will be two Table connection, look

SELECT *, CHARINDEX (@P, Strall @ p, # t.id), Substring (Strall, # T.ID, Charindex (@ p, strall @ p, # t.id) - # T.ID) from #e , # twhere substring (@P strall, # T.ID, 1) = @p

DROP TABLE #EDROP TABLE #T

转载请注明原文地址:https://www.9cbs.com/read-67470.html

New Post(0)