Sql 将数字转换为阿拉伯语单词
可能重复:Sql 将数字转换为阿拉伯语单词,sql,sql-server,Sql,Sql Server,可能重复: 我创建了一个表,其中包含0到99之间的数字; 对于这两个数字之间的数字,查询正在运行, 它也适用于这些数字: 100, 200, 1000, 2000, 1100, 2100, 1000000. 通常,它适用于大于100的数字,并且不包含我已经创建的表中的数字。。 对于所有其他数字,我得到“空”。 我认为问题出在变量@Units上,但我不能再关注它了 CREATE FUNCTION dbo.fnIntegerToWords(@Nb as BIGINT) RETURNS NVARC
我创建了一个表,其中包含0到99之间的数字; 对于这两个数字之间的数字,查询正在运行, 它也适用于这些数字: 100, 200, 1000, 2000, 1100, 2100, 1000000. 通常,它适用于大于100的数字,并且不包含我已经创建的表中的数字。。 对于所有其他数字,我得到“空”。 我认为问题出在变量@Units上,但我不能再关注它了
CREATE FUNCTION dbo.fnIntegerToWords(@Nb as BIGINT)
RETURNS NVARCHAR(1024)
AS
BEGIN
DECLARE @Millions as int
DECLARE @Remainder as int
DECLARE @Thousands as bigint
DECLARE @Hundreds as int
DECLARE @Units as int
DECLARE @word as nvarchar (1024)
DECLARE @result as nvarchar(1024)
set @Millions = @Nb/1000000
set @Units = @Nb %1000000
IF @Millions > 0
BEGIN
if @Millions = 1
set @result = N' مليون'
if @Units > 0
begin
set @Thousands = @Units / 1000
set @Units = @Units % 1000
if @Thousands > 0
begin
if @Thousands = 1
set @result = @result + N' و' + N'ألف'
else
if @Thousands = 2
set @result = @result + N' و' + N'ألفان'
else
if @Thousands between 100 and 199
BEGIN
set @Hundreds = @Thousands / 100
set @Remainder = @Thousands % 100
if @Remainder = 0
begin
set @result = @result + N' مائة ألف'
set @Thousands = 0
end
else
if @Remainder > 0
begin
set @result = @result + N' و' + N'مائة'
if @Remainder > 0
set @result = @result + N' و' + dbo.fnIntegerToWords(@Remainder) + N' ألف'
end
END
else
if @Thousands between 200 and 299
BEGIN
set @Hundreds = @Thousands / 100
set @Remainder = @Thousands % 100
if @Remainder = 0
begin
set @result = @result + N' و' + N' مئتان ألف'
set @Thousands = 0
end
else
if @Remainder > 0
begin
set @result = @result + N' و' + N' مئتان'
if @Remainder > 0
set @result = @result + N' و' + dbo.fnIntegerToWords(@Remainder) + N' ألف'
end
END
else
if @Thousands > 299
BEGIN
set @Hundreds = @Thousands / 100
set @Remainder = @Thousands % 100
if @Remainder = 0
begin
set @result = @result + N' و' + dbo.fnIntegerToWords(@Hundreds) + N' مائة ألف'
end
else
begin
set @result = @result + N' و' + dbo.fnIntegerToWords(@Hundreds) + N' مائة'
if @Remainder > 0
set @result = @result + N' و' + dbo.fnIntegerToWords(@Remainder)+ N' ألف'
end
END
else
if @Thousands between 3 and 99
set @result = @result + N' و' + dbo.fnIntegerToWords(@Thousands) + N' ألف'
END
if @Units > 0
Begin
set @Hundreds = @Units / 100
set @Units = @Units % 100
if @Hundreds > 0
BEGIN
if @Hundreds = 1
set @result = @result + N' و' + N' مائة'
else
if @Hundreds = 2
set @result = @result + N' و' + N' مئتان'
else
set @result = @result + N' و' + dbo.fnIntegerToWords(@Hundreds) + N' مائة'
END
if @Units > 0
set @result = @result + N' و' + dbo.fnIntegerToWords(@Units)
End
end
END
ELSE
IF @Millions = 0
BEGIN
set @Thousands = @Units /1000
set @Units = @Units %1000
IF @Thousands > 0
BEGIN
if @Thousands = 1
set @result = N' ألف'
else
if @Thousands = 2
set @result = N' ألفان'
else
if @Thousands between 100 and 199
BEGIN
set @Hundreds = @Thousands / 100
set @Remainder = @Thousands % 100
if @Remainder = 0
set @result = N' مائة ألف'
else
if @Remainder > 0
begin
set @result = N' مائة'
if @Remainder > 0
set @result = @result + N' و' + dbo.fnIntegerToWords(@Remainder) + N' ألف'
end
END
else
if @Thousands between 200 and 299
BEGIN
set @Hundreds = @Thousands / 100
set @Remainder = @Thousands % 100
if @Remainder = 0
begin
set @result = N' مئتان ألف'
end
else
if @Remainder > 0
begin
set @result = N' مئتان'
if @Remainder > 0
set @result = @result + N' و' + dbo.fnIntegerToWords(@Remainder) + N' ألف'
end
END
else
if @Thousands > 299
BEGIN
set @Hundreds = @Thousands / 100
set @Remainder = @Thousands % 100
if @Remainder = 0
begin
set @result = dbo.fnIntegerToWords(@Hundreds) + N' مائة ألف'
end
else
begin
set @result = dbo.fnIntegerToWords(@Hundreds) + N' مائة'
if @Remainder > 0
set @result = @result + N' و' + dbo.fnIntegerToWords(@Remainder) + N' ألف'
end
END
else
set @result = dbo.fnIntegerToWords(@Thousands) + N' ألف'
if @Units <> 0
BEGIN
set @Hundreds = @Units / 100
set @Units = @Units % 100
if @Hundreds > 0
BEGIN
if @Hundreds = 1
set @result = @result + N' و' + N' مائة'
else
if @Hundreds = 2
set @result = @result + N' و' + N' مئتان'
else
set @result = @result + N' و' + dbo.fnIntegerToWords(@Hundreds) + N' مائة'
END
if @Units > 0
set @result = @result + N' و' + dbo.fnIntegerToWords(@Units)
END
END
END
ELSE
IF @Thousands = 0
BEGIN
set @Hundreds = @Units / 100
set @Units = @Units % 100
if @Hundreds > 0
BEGIN
if @Hundreds = 1
set @result = N' مائة'
else
if @Hundreds = 2
set @result = N' مئتان'
else
set @result = dbo.fnIntegerToWords(@Hundreds) + N' مائة'
if @Units > 0
set @result = @result + N' و' + dbo.fnIntegerToWords(@Units)
END
else
set @result = (select COALESCE(word,'') from number where @Units=number)
END
RETURN @result
END
创建函数dbo.fintegertowords(@Nb作为BIGINT)
返回NVARCHAR(1024)
作为
开始
将@数百万声明为int
将@余数声明为int
将@数千声明为bigint
将@数百声明为int
将@Units声明为int
将@word声明为nvarchar(1024)
将@result声明为nvarchar(1024)
设置@百万=@Nb/1000000
设置@Units=@Nb%1000000
如果@百万>0
开始
如果@百万=1
设置@result=N'
如果@Units>0
开始
设置@数千=@Units/1000
设置@Units=@Units%1000
如果@数千>0
开始
如果@数千=1
设置@result=@result+N'و'+N'ألف'
其他的
如果@数千=2
设置@result=@result+N'و'+N'ألفان'
其他的
如果@1000介于100和199之间
开始
设置为@数百=@数千/100
设置@余数=@1000%100
如果@余数=0
开始
设置@result=@result+N'
设置@千=0
结束
其他的
如果@余数>0
开始
set@result=@result+N'و'+N'ما㶡'
如果@余数>0
set@result=@result+N'و'+dbo.fintegertowords(@restinutes)+N'أف'
结束
结束
其他的
如果@千介于200和299之间
开始
设置为@数百=@数千/100
设置@余数=@1000%100
如果@余数=0
开始
set@result=@result+N'و'+N'تتتنأف'
设置@千=0
结束
其他的
如果@余数>0
开始
设置@result=@result+N'و'+N'متتن'
如果@余数>0
set@result=@result+N'و'+dbo.fintegertowords(@restinutes)+N'أف'
结束
结束
其他的
如果@数千>299
开始
设置为@数百=@数千/100
设置@余数=@1000%100
如果@余数=0
开始
set@result=@result+N'و'+dbo.fn整数单词(@数百)+N'
结束
其他的
开始
set@result=@result+N'و'+dbo.fintegertowords(@数百)+N'ماة'
如果@余数>0
set@result=@result+N'و'+dbo.fintegertowords(@restinutes)+N'أف'
结束
结束
其他的
如果@千介于3和99之间
set@result=@result+N'و'+dbo.fintegertowords(@数千)+N'أف'
结束
如果@Units>0
开始
设置为@数百=@Units/100
设置@Units=@Units%100
如果@数百>0
开始
如果@数百=1
set@result=@result+N'و'+N'ما㶡'
其他的
如果@数百=2
设置@result=@result+N'و'+N'متتن'
其他的
set@result=@result+N'و'+dbo.fintegertowords(@数百)+N'ماة'
结束
如果@Units>0
set@result=@result+N'و'+dbo.fnigertowords(@Units)
终点
结束
结束
其他的
如果@百万=0
开始
设置@数千=@Units/1000
设置@Units=@Units%1000
如果@数千>0
开始
如果@数千=1
设置@result=N'ألف'
其他的
如果@数千=2
设置@result=N'
其他的
如果@1000介于100和199之间
开始
设置为@数百=@数千/100
设置@余数=@1000%100
如果@余数=0
设置@result=N'
其他的
如果@余数>0
开始
设置@result=N'مائ㶡'
如果@余数>0
set@result=@result+N'و'+dbo.fintegertowords(@restinutes)+N'أف'
结束
结束
其他的
如果@千介于200和299之间
开始
设置为@数百=@数千/100
设置@余数=@1000%100
如果@余数=0
开始
设置@result=N'
结束
其他的
如果@余数>0
开始
设置@result=N'
如果@余数>0
set@result=@result+N'و'+dbo.fintegertowords(@restinutes)+N'أف'
结束
结束
其他的
如果@数千>299
开始
设置为@数百=@数千/100
设置@余数=@1000%100
如果@余数=0
开始
set@result=dbo.fn整数单词(@数百)+N'
结束
其他的
开始
设置@result=dbo.fn整数单词(@数百)+N'
如果@
DECLARE @result as nvarchar(1024) = ''
DECLARE @result as nvarchar(1024);
SET @result = = ''