분할 UDF와 함께 CROSS APPLY을 사용하십시오. 나의 예를 위해 사용하고있는 스트링 스플리터는 here에서 나온다.
/* Create function for purposes of demo */
CREATE FUNCTION [dbo].[fnParseStringTSQL] (@string NVARCHAR(MAX),@separator NCHAR(1))
RETURNS @parsedString TABLE (string NVARCHAR(MAX))
AS
BEGIN
DECLARE @position int
SET @position = 1
SET @string = @string + @separator
WHILE charindex(@separator,@string,@position) <> 0
BEGIN
INSERT into @parsedString
SELECT substring(@string, @position, charindex(@separator,@string,@position) - @position)
SET @position = charindex(@separator,@string,@position) + 1
END
RETURN
END
go
/* Set up sample data */
declare @t table (
IR int,
CR varchar(100)
)
insert into @t
(IR, CR)
select 1, '1,2' union all
select 2, '3' union all
select 3, '4,5,6'
/* Here's the query that solves the problem */
select t.IR, p.string
from @t t
cross apply [dbo].[fnParseStringTSQL](t.CR,',') p
/* clean up after demo */
drop function [dbo].[fnParseStringTSQL]
굉장합니다. 감사. 나는 십자가를 더 볼 필요가있다! – thomas
물론 이것은 잘못된 형식의 데이터를 계속 사용하지 않는 관계형 모델로 데이터를 변환하는 경우에만 수행해야합니다. 이를 수행 할 필요가 시급히 재 설계해야 할 필요성을 나타냅니다. – HLGEM
@HLGEM : 아멘. –