Information générale
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
>I have a SELECT statement which uses a function that returns a numeric value as one of the fields, like so...
>
>SELECT table.fieldone, table.fieldthree, table.fieldthree,;
>GetAmount(table.duedate) AS howmuch ;
>FROM table ;
>INTO CURSOR cTemp
>
>The format of the function is like this:
>
>FUNCTION GetAmount
>LPARAMETERS
>LOCAL lnReturnValue
>STORE 0 TO lnReturnValue
>
>RETURN lnReturnValue
>
>The problem is this, I have used the debugger to confirm that the function returns values with decimals, like 524.56, BUT the amount that ends up in the "howmuch" field from the AS part of the SELECT statement is 525, not 524.56. So, how do I maintain the decimals when I get the value from a function called within a SELECT statement?
>
>Thanks.
Not sure what may be happening here but I got the following code to work for me...
create cursor cTemp (f1 c(5), f2 c(5), f3 n(5,2))
for lnx = 1 to 10
lcX = allt(str(lnX))
insert into cTemp (f1, f2, f3) VALUES (lcX, lcX, lnx/3.3)
endfor
SELECT cTemp.f1, cTemp.f2, GetAmount(cTemp.f3) AS howmuch ;
FROM cTemp ;
INTO CURSOR cTemp2
return
FUNCTION GetAmount
LPARAMETERS dDueDate
* LOCAL lnReturnValue
* STORE 0.55 TO lnReturnValue
* RETURN lnReturnValue
RETURN dDueDate
ENDFUNC
HTH
Michael
Précédent
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement