SQL Server TEXT、NTEXT字段拆分的问题
网络整理 - 07-27
SQL Server TEXT、NTEXT字段拆分的问题
以下为引用的内容:
SET NOCOUNT ON
CREATE TABLE #T (C NTEXT)
GO
INSERT INTO #T VALUES('')
GO
CREATE TABLE #T2 (C CHAR(8))
GO
DECLARE @S1 VARCHAR(8000),@S2 VARCHAR(8000),@I INT
SET @S1=''
SET @S2=''
SET @I=1
WHILE @I<=1000
BEGIN
SET @S1=@S1+'A'+RIGHT('0000000'+CAST(@I AS VARCHAR(5)),6)+','
SET @S2=@S2+'B'+RIGHT('0000000'+CAST(@I AS VARCHAR(5)),6)+','
SET @I=@I+1
END
DECLARE @P BINARY(16)
SELECT @P = TEXTPTR(C) FROM #T
UPDATETEXT #T.C @P NULL NULL @S1
UPDATETEXT #T.C @P NULL NULL @S2
SELECT DATALENGTH(C) FROM #T
DECLARE @DL INT
SET @DL = (SELECT DATALENGTH(C) FROM #T)/2
SET @I=1
WHILE @I <= @DL
BEGIN
INSERT INTO #T2 SELECT SUBSTRING(C,@I,7) FROM #T
SET @I=@I+8
END
SELECT * FROM #T2
/*
功能:实现split功能的函数
*/