MS-SQL 초성검색 함수
USE [Database명]
GO
/****** 개체: UserDefinedFunction [dbo].[GetChoSung2] 스크립트 날짜: 04/26/2012 08:48:59 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[GetChoSung2] (@vStr nvarchar(200))
RETURNS nvarchar(200)
as
begin
declare @vLen integer, @vPos integer;
declare @vCh nvarchar(1), @vRCh nvarchar(1);
declare @vRet nvarchar(200);
SET @vLen = Len(@vStr);
SET @vPos = 0;
SET @vRet = '';
While 0=0 begin
SET @vPos = @vPos + 1;
if ( @vPos > @vLen ) Break;
SET @vCh = Upper(SUBSTRING(@vStr, @vPos, 1));
if (@vCh >= '가' and @vCh <= '깋') SET @vRet = @vRet + 'ㄱ';
else if (@vCh >= '나' and @vCh <= '닣') SET @vRet = @vRet + 'ㄴ';
else if (@vCh >= '다' and @vCh <= '딯') SET @vRet = @vRet + 'ㄷ';
else if (@vCh >= '라' and @vCh <= '맇') SET @vRet = @vRet + 'ㄹ';
else if (@vCh >= '마' and @vCh <= '밓') SET @vRet = @vRet + 'ㅁ';
else if (@vCh >= '바' and @vCh <= '빟') SET @vRet = @vRet + 'ㅂ';
else if (@vCh >= '사' and @vCh <= '싷') SET @vRet = @vRet + 'ㅅ';
else if (@vCh >= '아' and @vCh <= '잏') SET @vRet = @vRet + 'ㅇ';
else if (@vCh >= '자' and @vCh <= '짛') SET @vRet = @vRet + 'ㅈ';
else if (@vCh >= '차' and @vCh <= '칳') SET @vRet = @vRet + 'ㅊ';
else if (@vCh >= '카' and @vCh <= '킿') SET @vRet = @vRet + 'ㅋ';
else if (@vCh >= '타' and @vCh <= '팋') SET @vRet = @vRet + 'ㅌ';
else if (@vCh >= '파' and @vCh <= '핗') SET @vRet = @vRet + 'ㅍ';
else if (@vCh >= '하' and @vCh <= '힣') SET @vRet = @vRet + 'ㅎ';
else if (@vCh >= '까' and @vCh <= '낗') SET @vRet = @vRet + 'ㄲ';
else if (@vCh >= '따' and @vCh <= '띻') SET @vRet = @vRet + 'ㄸ';
else if (@vCh >= '빠' and @vCh <= '삫') SET @vRet = @vRet + 'ㅃ';
else if (@vCh >= '싸' and @vCh <= '앃') SET @vRet = @vRet + 'ㅆ';
else if (@vCh >= '짜' and @vCh <= '찧') SET @vRet = @vRet + 'ㅉ';
else if (@vCh >= 'A' and @vCh <= 'Z') SET @vRet = @vRet + @vCh;
else if (@vCh >= '0' and @vCh <= '9') SET @vRet = @vRet + @vCh;
else SET @vRet = @vRet + @vCh;
end;
return @vRet;
END