Subject Number to Words in Indian Format-Help Me
Author Kailasapathi Senthil Babu
Hey,

Thanks To all,

I need to convert Numbers to  Words in Indian Format.  I am using Firebird 2.1.3 (Super Server).
I have created procedures for the conversion, These procedures are replicated from my VB6 Procedures. But i am getting a lot of errors during conversion.
Attached text file with SQL code for firebird procedures.

Please help me to solve this.

With regards
K.Senthil Babu



----------

SET TERM ^ ;
CREATE PROCEDURE INWORDS (
PARAMCURRENCY Numeric(18,2) )
RETURNS (
SRESULT Char(2000),
SLOOP Char(4000) )
AS
DECLARE VARIABLE STRCURR CHAR(15);
DECLARE VARIABLE PARAMSTR CHAR;
DECLARE VARIABLE PAISESTR CHAR(50);
DECLARE VARIABLE TEMPSTR1 CHAR(50);
DECLARE VARIABLE TEMPSTR2 CHAR(50);
DECLARE VARIABLE TEMPSTR3 CHAR(50);
DECLARE VARIABLE INTPOSITION integer;
DECLARE VARIABLE counter integer;
DECLARE VARIABLE CURRSTR CHAR(50);
DECLARE VARIABLE STRR CHAR(1);
DECLARE VARIABLE STRL CHAR(1);
DECLARE VARIABLE CUTFROM integer;
DECLARE VARIABLE LVL integer;
DECLARE VARIABLE FINALSTR CHAR(4000);
BEGIN
PARAMCURRENCY=ROUND(ABS(PARAMCURRENCY),2);
STRCURR=TRIM(CAST(PARAMCURRENCY AS CHAR(15)));
if (PARAMCURRENCY-FLOOR(PARAMCURRENCY)<>0) THEN
BEGIN
INTPOSITION=POSITION('.' IN STRCURR)+1;
STRR=substring(STRCURR FROM :INTPOSITION FOR 1);
INTPOSITION=0;
INTPOSITION=POSITION('.' IN STRCURR)+2;
STRL=substring(STRCURR FROM :INTPOSITION FOR 1);
execute procedure NUMTOWORDS 1,:STRR,:STRL,1 returning_values TEMPSTR3;
PAISESTR=' And ' || trim(TEMPSTR3);
END
STRCURR=FLOOR(PARAMCURRENCY);
CUTFROM=char_length(FLOOR(PARAMCURRENCY));
CURRSTR='';
STRR='';
STRL='';
COUNTER=1;
LVL=1;
SRESULT='A-';
WHILE (COUNTER <=char_length(STRCURR)) DO
BEGIN
CURRSTR='';
STRR='';
STRL='';

IF (LVL=2) then
BEGIN
STRL =substring(STRCURR FROM CUTFROM FOR 1);
SRESULT=TRIM(SRESULT) || '-C2-' || STRL;
STRR='';
COUNTER=COUNTER+1;
CUTFROM=CUTFROM-1;
END
ELSE IF (LVL<>2) then
BEGIN
SRESULT=TRIM(SRESULT) || '-D2-' || TRIM(STRCURR) || 'CUTFROM' || CUTFROM;
STRR=substring(STRCURR FROM CUTFROM FOR 1);
SRESULT=TRIM(SRESULT) || '-A1-' || STRR;
IF (CUTFROM-1>0) then
BEGIN
CUTFROM=CUTFROM-1;
STRL =tRIM(substring(STRCURR FROM CUTFROM-1 FOR 1));
CUTFROM=CUTFROM+1;
SRESULT=TRIM(SRESULT) || '-B2-' || STRL;
END
COUNTER=COUNTER+2;
CUTFROM=CUTFROM-2;
END
EXECUTE procedure NUMTOWORDS( :LVL,:STRL,:STRR,0 )returning_values (:CURRSTR);
LVL=LVL+1;
IF (trim(FINALSTR)='') then
FINALSTR =Trim(CURRSTR);
else
BEGIN
FINALSTR =Trim(CURRSTR) || ' ' || Trim(FINALSTR);
END
END
/*SRESULT =TRIM(SRESULT) || ' ---- ' || TRIM(FINALSTR) || ' ' || TRIM(PAISESTR); */
SUSPEND;
END^
SET TERM ; ^

GRANT EXECUTE
ON PROCEDURE INWORDS TO SYSDBA;



SET TERM ^ ;
CREATE PROCEDURE NUMTOWORDS (
LVL Integer,
STR1 Char(1),
STR2 Char(1),
BLNISAFTERDEC Smallint )
RETURNS (
SRESULT Char(50) )
AS
DECLARE variable STRTEMP CHAR(25);
DECLARE variable STRTEMP1 CHAR(25);
DECLARE variable STRTEMP2 CHAR(25);
BEGIN
if (lvl=2) then
execute procedure NUMNAME :str1, 'Units' returning_values :STRTEMP;
else if (lvl<>2) then
BEGIN
SRESULT=STR1;
IF (STR2<>'') then
IF (TRIM(STR1)='') then
execute procedure NUMNAME :str2, 'Units' returning_values :STRTEMP;
ELSE IF (STR1=0) then
execute procedure NUMNAME :str2, 'Units' returning_values :STRTEMP;
ELSE IF (STR1=1) then
execute procedure NUMNAME :str2, 'Teens' returning_values :STRTEMP;
ELSE
BEGIN
IF (CAST(STR2 AS CHAR)='0') then
execute procedure NUMNAME :str1, 'Tys' returning_values :STRTEMP;
else
BEGIN
execute procedure NUMNAME :str1, 'Tys' returning_values :STRTEMP1;
execute procedure NUMNAME :str2, 'Units' returning_values :STRTEMP2;
STRTEMP=tRIM(STRTEMP1) || ' ' || tRIM(STRTEMP2);
END
END
ELSE IF (STR2='') then
execute procedure NUMNAME :str1, 'Units' returning_values :STRTEMP;
STRTEMP=TRIM(STRTEMP);
END
IF (BLNISAFTERDEC=1) then
SRESULT =TRIM(STRTEMP);
else IF (BLNISAFTERDEC=0) then
BEGIN
execute procedure VALUENAME :STRTEMP,:LVL returning_values :SRESULT;
SRESULT=TRIM(SRESULT);
END

SUSPEND;
END^
SET TERM ; ^

GRANT EXECUTE
ON PROCEDURE NUMTOWORDS TO SYSDBA;

SET TERM ^ ;
CREATE PROCEDURE VALUENAME (
INVAL Char(100),
LVL Integer )
RETURNS (
SRETURN Char(4096) )
AS
BEGIN
IF (INVAL <>'' AND INVAL<>'Zero') then
IF (LVL =1) THEN
SRETURN=TRIM(INVAL);
ELSE IF (LVL = 2) THEN
SRETURN=TRIM(INVAL) || ' ' || 'Hundred';
ELSE IF (LVL =3) THEN
SRETURN=TRIM(INVAL) || ' ' || ' Thousand ';
ELSE IF (LVL = 4) THEN
SRETURN=TRIM(INVAL) || ' ' || ' Lakh ';
ELSE IF (LVL = 5) THEN
SRETURN=TRIM(INVAL) || ' ' || ' Crore ';

SUSPEND;
END^
SET TERM ; ^

GRANT EXECUTE
ON PROCEDURE VALUENAME TO SYSDBA;

SET TERM ^ ;
CREATE PROCEDURE NUMNAME (
S Char(1),
LVL Char(5) )
RETURNS (
SRESULT Char(25) )
AS
BEGIN
IF (TRIM(S)<>'' OR TRIM(LVL)<>'') then
IF (LVL='Units') then
BEGIN
IF (S='0') then sresult='Zero';
ELSE IF (S='1') THEN SRESULT='One';
ELSE IF (S='2') THEN SRESULT='Two';
ELSE IF (S='3') THEN SRESULT='Three';
ELSE IF (S='4') THEN SRESULT='Four';
ELSE IF (S='5') THEN SRESULT='Five';
ELSE IF (S='6') THEN SRESULT='Six';
ELSE IF (S='7') THEN SRESULT='Seven';
ELSE IF (S='8') THEN SRESULT='Eight';
ELSE IF (S='9') THEN SRESULT='Nine';
END
ELSE IF (LVL='Teens') then
BEGIN
IF (S='0') then sresult='Ten';
ELSE IF (S='1') THEN SRESULT='Eleven';
ELSE IF (S='2') THEN SRESULT='Twelve';
ELSE IF (S='3') THEN SRESULT='Thirteen';
ELSE IF (S='4') THEN SRESULT='Fourteen';
ELSE IF (S='5') THEN SRESULT='Fifteen';
ELSE IF (S='6') THEN SRESULT='Sixteen';
ELSE IF (S='7') THEN SRESULT='Seventeen';
ELSE IF (S='8') THEN SRESULT='Eighteen';
ELSE IF (S='9') THEN SRESULT='Nineteen';
END
ELSE IF (LVL='Tys') then
BEGIN
IF (S='2') THEN SRESULT='Twenty';
ELSE IF (S='3') THEN SRESULT='Thirty ';
ELSE IF (S='4') THEN SRESULT='Fourty ';
ELSE IF (S='5') THEN SRESULT='Fifty ';
ELSE IF (S='6') THEN SRESULT='Sixty ';
ELSE IF (S='7') THEN SRESULT='Seventy ';
ELSE IF (S='8') THEN SRESULT='Eighty ';
ELSE IF (S='9') THEN SRESULT='Ninety ';
END

ELSE
SRESULT='';
SUSPEND;
END^
SET TERM ; ^

GRANT EXECUTE
ON PROCEDURE NUMNAME TO SYSDBA;






[Non-text portions of this message have been removed]