CTE(Common Table Expressions)を使用して入力値をループします。他にも利用可能な方法がありますが、文字列入力を分割してテーブルに変換したい場合は、
DECLARE @DemoTable table (Layout varchar(2000))
INSERT @DemoTable VALUES ('email1[a]test.com;email2[a]test.com;email3[a]test.com;email4[a]test.com;email5[a]test.com;email6[a]test.com;email7[a]test.com;email8[a]test.com;email9[a]test.com;email10[a]test.com;email11[a]test.com;email12[a]test.com;email13[a]test.com;email14[a]test.com;email15[a]test.com;email16[a]test.com;email17[a]test.com;email18[a]test.com;email19[a]test.com;email20[a]test.com;email21[a]test.com;email22[a]test.com;email23[a]test.com;email24[a]test.com;email25[a]test.com;email26[a]test.com;email27[a]test.com;email28[a]test.com;email29[a]test.com;email30[a]test.com;email31[a]test.com;email32[a]test.com;email33[a]test.com;email34[a]test.com;email35[a]test.com;')
DECLARE @StringToTable table (email varchar(200))
DECLARE @Concatenated VARCHAR(2000)
SET @Concatenated=''
;WITH StringToTable AS
( SELECT LEFT(Layout,CHARINDEX(';',Layout)) AS Email
, RIGHT(Layout,LEN(Layout)-CHARINDEX(';',Layout)) StringToProcess
FROM @DemoTable
WHERE Layout IS NOT NULL AND CHARINDEX(';',Layout)>0
UNION ALL
SELECT LEFT(StringToProcess,CHARINDEX(';',StringToProcess))
, RIGHT(StringToProcess,LEN(StringToProcess)-CHARINDEX(';',StringToProcess))
FROM StringToTable
WHERE StringToProcess IS NOT NULL AND CHARINDEX(';',StringToProcess)>0
)
INSERT INTO @StringToTable(email)
SELECT TOP 10 Email FROM StringToTable--TOP 10 is to get the 10 mentioned in the question - you can change the order by to affect which 10 you wish to use.
SELECT Email FROM @StringToTable
あなたはこのようにそれを行うことができます文字列に行を再統合する必要がある場合:10から10に
SELECT @Concatenated = @Concatenated + Email FROM @StringToTable
SELECT @Concatenated
? –
私はあなたにこの質問の詳細を明らかにする –