본문 바로가기
Database/MS-Sql Lecture

ArrayToSingle 유저펑션

by 현이빈이 2008. 8. 22.
반응형
Create Function UFN_ArrayToSingle (@ArrayData varchar(8000))
Returns @singleData Table (singleData varchar(100))
as
begin
	declare @tblTemp Table (data varchar(100))
	
	declare @CutData	varchar(50)
	declare @DelCutData	varchar(50)
	declare @SPosition	int

	set @ArrayData = @ArrayData + '|'

	while len(@ArrayData) > 0
	begin			
		set @SPosition = charindex('|',@ArrayData)
		set @CutData = left(@ArrayData, @SPosition - 1)
		set @DelCutData = @CutData + '|'
		set @ArrayData = replace(@ArrayData,@DelCutData,'')
		insert into @tblTemp (data) select @CutData
	end

	insert into @singleData 
	select data from @tblTemp
	Return
end


select * from dbo.UFN_ArrayToSingle('aaa|bbb')
-----------------------------
출처 sqler.pe.kr
반응형