DATABASE / SQL Server 2005 GSM No Kontrolü
CREATE FUNCTION [dbo].[fn_GSM]
(
@deger nvarchar(1000)
)
RETURNS @RtnValue table
(
GSM nvarchar(10),
Durum bit
)
AS
BEGIN
SET @deger = LTRIM(RTRIM(@deger))
DECLARE @karakterler NVARCHAR(10)
SET @karakterler = ‘0123456789’
DECLARE @deger_ NVARCHAR(1000)
SET @deger_ = ”
DECLARE @say INT
SET @say = 1
DECLARE @harf NVARCHAR(1)
WHILE (@say < = LEN(@deger))
BEGIN
SET @harf = ''
SET @harf = SUBSTRING(@deger, @say, 1)
IF (CHARINDEX(@harf, @karakterler) != 0)
BEGIN
SET @deger_ = @deger_ + @harf
END
SET @say = @say + 1
END
if (Substring(@deger_, 1, 1) = '5')
SET @deger_ = Substring(@deger_, 1, Len(@deger_))
else if (Substring(@deger_, 1, 2) = '05')
SET @deger_ = Substring(@deger_, 2, Len(@deger_))
else if (Substring(@deger_, 1, 3) = '905')
SET @deger_ = Substring(@deger_, 3, Len(@deger_))
else if (Substring(@deger_, 1, 4) = '0905')
SET @deger_ = Substring(@deger_, 4, Len(@deger_))
else if (Substring(@deger_, 1, 5) = '00905')
SET @deger_ = Substring(@deger_, 5, Len(@deger_))
else
SET @deger_ = ''
if (Len(@deger_) >= 10)
Insert Into @RtnValue (GSM, Durum) values (Substring(@deger_, 1, 10), 1)
else
Insert Into @RtnValue (GSM, Durum) values (”, 0)
Return
END
TurkIRC ©