如何为以下代码创建存储过程。
use Test
DECLARE @Str VARCHAR(120)
SET @Str = 'company name'
DECLARE @End INT
DECLARE @Split INT
SET @Split = 40
declare @SomeTable table
(
Content varchar(120)
)
WHILE (LEN(@Str) > 0)
BEGIN
IF (LEN(@Str) > @Split)
BEGIN
SET @End = LEN(LEFT(@Str, @Split)) - CHARINDEX(' ', REVERSE(LEFT(@Str, @Split)))
INSERT INTO @SomeTable VALUES (RTRIM(LTRIM(LEFT(LEFT(@Str, @Split), @End))))
SET @Str = SUBSTRING(@Str, @End + 1, LEN(@Str))
END
ELSE
BEGIN
INSERT INTO @SomeTable VALUES (RTRIM(LTRIM(@Str)))
SET @Str = ''
END
END
SELECT *
FROM @SomeTable