SAMPLE
非常に特殊な用途ですが
下記の文字列を指定の字数ずつ分離してレコードに格納します。
XXXYYYWWW
SQL SERVER
CREATE FUNCTION [dbo].[Onecharacter]
(
@string NVARCHAR(4000),
@n INT
)
RETURNS TABLE
AS
RETURN
(
WITH Onecharacter(stpos,endpos)
AS(
SELECT 1 AS stpos, 1+@n AS endpos
UNION ALL
SELECT endpos,endpos+@n
FROM Onecharacter
WHERE endpos > 0
AND endpos < LEN(@string)+1
)
SELECT 'data' = SUBSTRING(@string,stpos,COALESCE(NULLIF(endpos,0),LEN(@String)+1)-stpos)
FROM Onecharacter
)
HOW TO USE
DECLARE @string NVARCHAR(100) = 'XXXYYYWWW';
SELECT data
FROM dbo.Onecharacter(@string,3)