SQL Server 2000 を使用せざるを得ない場合、 andの 4000/8000 文字制限を超えるには、text
orフィールドを使用する必要があります。 ntext
nvarchar
varchar
text
とフィールドで通常の文字列コマンドを使用できないためntext
、非常に混乱します。
各ストアド プロシージャを 1 行に配置したい場合は、次の方法を試すことができます。
以下のコードは忌まわしいものです。基本クエリを取得し、カーソルを使用してREADTEXT
、UPDATETEXT
ストアド プロシージャのリストを 1 行で作成しました。コード内のコメントは、私が何をしようとしているのかを特定するのに役立つはずです。
これは 100% テストされていないため、動作しない場合はお知らせください。
-- Gonzalo's original code --
SELECT sm.id, COUNT(sm.colid) AS Cantidad
INTO #SPrepeated
FROM syscomments AS sm INNER JOIN
sysobjects AS so ON sm.id = so.id
WHERE (so.status >= 0) AND (so.xtype = 'P') AND (so.category = 0)
GROUP BY sm.id, so.name
HAVING (COUNT(sm.colid) > 1)
SELECT sm.id, sm.colid, OBJECT_NAME(sm.id) AS object_name,
cast(sm.text as ntext) as [text]
into #Tresult
FROM syscomments AS sm
JOIN sysobjects AS so ON sm.id = so.id
JOIN #SPrepeated as spr ON so.id = spr.id
WHERE (so.status >= 0) AND (so.xtype = 'P')
-- Create our #TresultSingle temporary table structure --
SELECT TOP 1 [id], object_name, cast([text] as ntext) as [text]
INTO #TresultSingle
FROM #Tresult
-- Clear out the table, ready to insert --
TRUNCATE TABLE #TresultSingle
DECLARE @id int, @previd int, @colid int, @objectname nvarchar(4000),
@text nvarchar(4000)
DECLARE @ptrval varbinary(16), @offset int
SET @text = ''
-- Begin cursor, and start praying --
DECLARE ResultCursor CURSOR
FOR
SELECT [id], colid, [object_name], [text]
FROM #Tresult
ORDER BY [id], colid
OPEN ResultCursor
FETCH NEXT FROM ResultCursor
INTO @id, @colid, @objectname, @text
INSERT INTO #TresultSingle
SELECT @id, @objectname, @text
WHILE @@FETCH_STATUS = 0
BEGIN
-- If the ID has changed, create a new record in #TresultSingle --
IF @id <> @previd
BEGIN
INSERT INTO #TresultSingle
SELECT @id, @objectname, @text
END
ELSE
BEGIN
-- Get the textpointer of the current @id --
SELECT @ptrval = TEXTPTR(text)
FROM #TresultSingle
WHERE [id] = @id
-- Set our offset for inserting text --
SET @offset = 4000 * (@colid - 1)
-- Add the new text to the end of the existing text --
UPDATETEXT #TresultSingle.text @ptrval @offset 0 @text
END
SET @previd = @id
FETCH NEXT FROM ResultCursor
INTO @id, @colid, @objectname, @text
END
CLOSE ResultCursor
DEALLOCATE ResultCursor
SELECT * FROM #TresultSingle
DROP TABLE #TresultSingle
drop table #Tresult
drop table #SPrepeated