|
19.04.2011, 09:49
#37221911
Ссылка:
Ссылка на сообщение:
Ссылка с названием темы:
|
|
|
|
Lexx_SQL,
Один из вариантов, попробовать на стороне сервера. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. 59. 60. 61. 62. 63. 64. 65. 66. 67. 68. 69. 70. 71. 72.
-- Здесь надо одновременно задействовать обе функции, иначе Error
drop function NumPhrase
drop function dbo.RubPhrase
go
CREATE function NumPhrase (@Num BIGINT, @IsMaleGender bit= 1 )
returns varchar( 255 )
as
begin
declare @nword varchar( 255 ), @th tinyint, @gr smallint, @d3 tinyint, @d2 tinyint, @d1 tinyint
if @Num < 0 return '*** Error: Negative value' else if @Num= 0 return 'Ноль'
/* особый случай */
while @Num> 0
begin
set @th=IsNull(@th, 0 )+ 1 set @gr=@Num% 1000 set @Num=(@Num-@gr)/ 1000
if @gr> 0
begin
set @d3=(@gr-@gr% 100 )/ 100
set @d1=@gr% 10
set @d2=(@gr-@d3* 100 -@d1)/ 10
if @d2= 1 set @d1= 10 +@d1
set @nword=case @d3
when 1 then ' сто' when 2 then ' двести' when 3 then ' триста'
when 4 then ' четыреста' when 5 then ' пятьсот' when 6 then ' шестьсот'
when 7 then ' семьсот' when 8 then ' восемьсот' when 9 then ' девятьсот' else '' end
+case @d2
when 2 then ' двадцать' when 3 then ' тридцать' when 4 then ' сорок'
when 5 then ' пятьдесят' when 6 then ' шестьдесят' when 7 then ' семьдесят'
when 8 then ' восемьдесят' when 9 then ' девяносто' else '' end
+case @d1
when 1 then (case when @th= 2 or (@th= 1 and @IsMaleGender= 0 ) then ' одна' else ' один' end)
when 2 then (case when @th= 2 or (@th= 1 and @IsMaleGender= 0 ) then ' две' else ' два' end)
when 3 then ' три' when 4 then ' четыре' when 5 then ' пять'
when 6 then ' шесть' when 7 then ' семь' when 8 then ' восемь'
when 9 then ' девять' when 10 then ' десять' when 11 then ' одиннадцать'
when 12 then ' двенадцать' when 13 then ' тринадцать' when 14 then ' четырнадцать'
when 15 then ' пятнадцать' when 16 then ' шестнадцать' when 17 then ' семнадцать'
when 18 then ' восемнадцать' when 19 then ' девятнадцать' else '' end
+case @th
when 2 then ' тысяч' +(case when @d1= 1 then 'а' when @d1 in ( 2 , 3 , 4 ) then 'и' else '' end)
when 3 then ' миллион' when 4 then ' миллиард' when 5 then ' триллион' when 6 then ' квадриллион' when 7 then ' квинтиллион'
else '' end
+case when @th in ( 3 , 4 , 5 , 6 , 7 ) then (case when @d1= 1 then '' when @d1 in ( 2 , 3 , 4 ) then 'а' else 'ов' end) else '' end
+IsNull(@nword,'')
end
end
return upper(substring(@nword, 2 , 1 ))+substring(@nword, 3 ,len(@nword)- 2 )
end
go
CREATE function dbo.RubPhrase (@Value money)
returns varchar( 255 )
as
begin
declare @rpart bigint, @rattr tinyint, @cpart tinyint, @cattr tinyint
set @rpart=floor(@Value) set @rattr=@rpart% 100
if @rattr> 19 set @rattr=@rattr% 10
set @cpart=(@Value-@rpart)* 100
if @cpart> 19 set @cattr=@cpart% 10 else set @cattr=@cpart
return dbo.NumPhrase(@rpart, 1 )+' рубл'
+case when @rattr= 1 then 'ь' when @rattr in ( 2 , 3 , 4 ) then 'я' else 'ей' end+' '
+right('0'+cast(@cpart as varchar( 2 )), 2 )+' копе'
+case when @cattr= 1 then 'йка' when @cattr in ( 2 , 3 , 4 ) then 'йки' else 'ек' end
end
go
set nocount on
declare @d float = 5868191 . 32
select dbo.RubPhrase(@d) [s1]
select dbo.RubPhrase( 305 ) [s2]
Похожая тема, где задействованы эти функции:
RS2008 Странный вывод на печать чисел записанный прописью
|
|
|