Note that there are some explanatory texts on larger screens.

plurals
  1. POConverting numbers to words in Arabic
    primarykey
    data
    text
    <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/14040702/recursive-function-wont-work-again-sql">recursive function.. won’t work again SQL</a> </p> </blockquote> <p>I created a table containing numbers between 0 and 99; for the numbers between these two numbers the query is working, and it's working for these numbers too: 100, 200, 1000, 2000, 1100, 2100, 1000000. In general it works for the numbers >100 and doesn't contain a number from the table that I already created.. and for all the other numbers I get 'null'. I think the problem is in the variable @Units but I can't focus on that anymore.</p> <pre><code>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 &gt; 0 BEGIN if @Millions = 1 set @result = N' مليون' if @Units &gt; 0 begin set @Thousands = @Units / 1000 set @Units = @Units % 1000 if @Thousands &gt; 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 &gt; 0 begin set @result = @result + N' و' + N'مائة' if @Remainder &gt; 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 &gt; 0 begin set @result = @result + N' و' + N' مئتان' if @Remainder &gt; 0 set @result = @result + N' و' + dbo.fnIntegerToWords(@Remainder) + N' ألف' end END else if @Thousands &gt; 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 &gt; 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 &gt; 0 Begin set @Hundreds = @Units / 100 set @Units = @Units % 100 if @Hundreds &gt; 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 &gt; 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 &gt; 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 &gt; 0 begin set @result = N' مائة' if @Remainder &gt; 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 &gt; 0 begin set @result = N' مئتان' if @Remainder &gt; 0 set @result = @result + N' و' + dbo.fnIntegerToWords(@Remainder) + N' ألف' end END else if @Thousands &gt; 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 &gt; 0 set @result = @result + N' و' + dbo.fnIntegerToWords(@Remainder) + N' ألف' end END else set @result = dbo.fnIntegerToWords(@Thousands) + N' ألف' if @Units &lt;&gt; 0 BEGIN set @Hundreds = @Units / 100 set @Units = @Units % 100 if @Hundreds &gt; 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 &gt; 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 &gt; 0 BEGIN if @Hundreds = 1 set @result = N' مائة' else if @Hundreds = 2 set @result = N' مئتان' else set @result = dbo.fnIntegerToWords(@Hundreds) + N' مائة' if @Units &gt; 0 set @result = @result + N' و' + dbo.fnIntegerToWords(@Units) END else set @result = (select COALESCE(word,'') from number where @Units=number) END RETURN @result END </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload