Selam Arkadaslar,
Fatura dizaynlarinin diptoplamlarinda gördügümüz rakamlari yaziya çevrim yapan bir fonksiyona ihtiyacim vardi. Internetten arastirdigimda TL ve Kr çevrimi yapabilen bir sql fonksiyonu bulamadim. Bu nedenle kodlamam gerekti. Sizlerde tekrardan Amerika'yi kesfetmeyin diye paylasmak istedim.
CREATE FUNCTION [dbo].[RakamOku] (@Sayi decimal(10,2))
RETURNS nvarchar(300)
AS
BEGIN
DECLARE @N int,@i int,@UCHANE int,@YED nvarchar(300),@UCLUHANE nvarchar(300), @Kurus int,
@HangiBasamak int,@Negatif bit,@BasamakYaz bit,@SONUC nvarchar(300),@SONUCKR nvarchar(300)
SET @Kurus=RIGHT(@Sayi,len(@Sayi)-CHARINDEX('.',@Sayi,1))
SET @Sayi=LEFT(@Sayi,CHARINDEX('.',@Sayi,1)-1)
SET @N=9
SET @SONUC=NULL
BEGIN
SET @SONUC=''
IF (@Sayi=0) SET @SONUC='SIFIR' ELSE BEGIN
IF (@Sayi<0) BEGIN
SET @Negatif=1
SET @Sayi=-@Sayi
END ELSE SET @Negatif=0
SET @HangiBasamak=0;
WHILE (@Sayi>0) BEGIN
SET @UCHANE=@Sayi % 1000
SET @Sayi=@Sayi / 1000
IF (@UCHANE>0) SET @BasamakYaz=1 ELSE SET @BasamakYaz=0
IF ((@HangiBasamak=1) and (@UCHANE=1)) SET @UCLUHANE=''
ELSE BEGIN
SET @UCLUHANE=''
SET @i=@UCHANE%10 SET @UCHANE=@UCHANE/10
SET @UCLUHANE=CASE @i
WHEN 1 THEN 'BIR'
WHEN 2 THEN 'IKI'
WHEN 3 THEN 'UC'
WHEN 4 THEN 'DORT'
WHEN 5 THEN 'BES'
WHEN 6 THEN 'ALTI'
WHEN 7 THEN 'YEDI'
WHEN 8 THEN 'SEKIZ'
WHEN 9 THEN 'DOKUZ'
ELSE '' END
SET @i=@UCHANE%10 SET @UCHANE=@UCHANE/10
SET @UCLUHANE=CASE @i
WHEN 1 THEN 'ON'
WHEN 2 THEN 'YIRMI'
WHEN 3 THEN 'OTUZ'
WHEN 4 THEN 'KIRK'
WHEN 5 THEN 'ELLI'
WHEN 6 THEN 'ALTMIS'
WHEN 7 THEN 'YETMIS'
WHEN 8 THEN 'SEKSEN'
WHEN 9 THEN 'DOKSAN'
ELSE '' END+@UCLUHANE
SET @i=@UCHANE%10
IF (@i>0) SET @YED='YUZ' ELSE SET @YED=''
IF (@i>1) SET @YED=CASE @i
WHEN 1 THEN 'BIR'
WHEN 2 THEN 'IKI'
WHEN 3 THEN 'UC'
WHEN 4 THEN 'DORT'
WHEN 5 THEN 'BES'
WHEN 6 THEN 'ALTI'
WHEN 7 THEN 'YEDI'
WHEN 8 THEN 'SEKIZ'
WHEN 9 THEN 'DOKUZ'
ELSE '' END+@YED
SET @UCLUHANE=@YED+@UCLUHANE;
END
IF (@BasamakYaz=1) SET @SONUC=@UCLUHANE+CASE @HangiBasamak
WHEN 1 THEN 'BIN'
WHEN 2 THEN 'MILYON'
WHEN 3 THEN 'MILYAR'
WHEN 4 THEN 'TRILYON'
WHEN 5 THEN 'KATRILYON'
WHEN 6 THEN 'KENTRILYON'
WHEN 7 THEN 'SEKSTILYON'
WHEN 8 THEN 'SEPTILYON'
WHEN 9 THEN 'OKTILYON'
ELSE '' END+@SONUC
SET @HangiBasamak=@HangiBasamak+1
END
IF (@Negatif=1) SET @SONUC='EKSI'+@SONUC
END
SET @SONUC=@SONUC +' TL'
END
----------------
SET @N=9
SET @SONUCKR=NULL
BEGIN
SET @SONUCKR=''
IF (@Kurus=0) SET @SONUCKR='' ELSE BEGIN
IF (@Kurus<0) BEGIN
SET @Negatif=1
SET @Kurus=-@Kurus
END ELSE SET @Negatif=0
SET @HangiBasamak=0;
WHILE (@Kurus>0) BEGIN
SET @UCHANE=@Kurus % 1000
SET @Kurus=@Kurus / 1000
IF (@UCHANE>0) SET @BasamakYaz=1 ELSE SET @BasamakYaz=0
IF ((@HangiBasamak=1) and (@UCHANE=1)) SET @UCLUHANE=''
ELSE BEGIN
SET @UCLUHANE=''
SET @i=@UCHANE%10 SET @UCHANE=@UCHANE/10
SET @UCLUHANE=CASE @i
WHEN 1 THEN 'BIR'
WHEN 2 THEN 'IKI'
WHEN 3 THEN 'UC'
WHEN 4 THEN 'DORT'
WHEN 5 THEN 'BES'
WHEN 6 THEN 'ALTI'
WHEN 7 THEN 'YEDI'
WHEN 8 THEN 'SEKIZ'
WHEN 9 THEN 'DOKUZ'
ELSE '' END
SET @i=@UCHANE%10 SET @UCHANE=@UCHANE/10
SET @UCLUHANE=CASE @i
WHEN 1 THEN 'ON'
WHEN 2 THEN 'YIRMI'
WHEN 3 THEN 'OTUZ'
WHEN 4 THEN 'KIRK'
WHEN 5 THEN 'ELLI'
WHEN 6 THEN 'ALTMIS'
WHEN 7 THEN 'YETMIS'
WHEN 8 THEN 'SEKSEN'
WHEN 9 THEN 'DOKSAN'
ELSE '' END+@UCLUHANE
SET @i=@UCHANE%10
IF (@i>0) SET @YED='YUZ' ELSE SET @YED=''
IF (@i>1) SET @YED=CASE @i
WHEN 1 THEN 'BIR'
WHEN 2 THEN 'IKI'
WHEN 3 THEN 'UC'
WHEN 4 THEN 'DORT'
WHEN 5 THEN 'BES'
WHEN 6 THEN 'ALTI'
WHEN 7 THEN 'YEDI'
WHEN 8 THEN 'SEKIZ'
WHEN 9 THEN 'DOKUZ'
ELSE '' END+@YED
SET @UCLUHANE=@YED+@UCLUHANE;
END
IF (@BasamakYaz=1) SET @SONUCKR=@UCLUHANE+CASE @HangiBasamak
WHEN 1 THEN 'BIN'
WHEN 2 THEN 'MILYON'
WHEN 3 THEN 'MILYAR'
WHEN 4 THEN 'TRILYON'
WHEN 5 THEN 'KATRILYON'
WHEN 6 THEN 'KENTRILYON'
WHEN 7 THEN 'SEKSTILYON'
WHEN 8 THEN 'SEPTILYON'
WHEN 9 THEN 'OKTILYON'
ELSE '' END+@SONUCKR
SET @HangiBasamak=@HangiBasamak+1
END
IF (@Negatif=1) SET @SONUCKR='EKSI'+@SONUCKR
END
SET @SONUCKR=CASE WHEN LEN(@SONUCKR)>0 THEN ', ' + @SONUCKR + ' Kr' ELSE '' END
END
----------------
RETURN @SONUC+@SONUCKR
END
------------- Rifat Gündüz
www.netsis.com.tr
|