Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to use MAX() in a calculated field?
Message
From
26/01/2007 10:09:41
 
General information
Forum:
Visual FoxPro
Category:
Stonefield
Environment versions
Visual FoxPro:
VFP 9 SP1
Miscellaneous
Thread ID:
01189404
Message ID:
01189613
Views:
6
>>>>>>
>>>>>>Dmitry,
>>>>>>
>>>>>>Suggestions - may be wrong, since I do not know SDT
>>>>>>
>>>>>>
>>>>>>(1)
>>>>>>select eval('max(d2-d1, 0)')
>>>>>>
>>>>>>(2) To get rid of the asterisks, force the field length
>>>>>>select ntom(eval('max(d2-d1, 0)')) from test
>>>>>>
>>>>>>works as well
>>>>>>select mton(eval('max(d2-d1, 0)')) from test
>>>>>>
>>>>>>and this also
>>>>>>select mton(eval('max(ntom(d2-d1), $0)')) from test
>>>>>>
>>>>>
>>>>>Gregory,
>>>>>
>>>>>In SDT I can only specify the calculated field expression. For example, DATE_FLD1 - DATE_FLD2, or IIF(something,choice1,choice2), etc. And I can't enter "select" in this expression. Because this expression will be used in the auto report generator with a SELECT statement. And as I found out, somehow the SELECT used by SFReports does not like the IIF() expression as even if I hard-code number 1 as a return choice from IIF(), the report shows a bunch of asterisks.
>>>>>
>>>>>Thank you for your suggestions.
>>>>
>>>>
>>>>Then, can you specify mton(eval('max(ntom(d2-d1), $0)')) as the calculated field expression ?
>>>>
>>>>Seems to me that the expression is fed into an sql statement (original error)
>>>
>>>I will try your suggestion. But why do you use ntom() and mton()? Couldn't you just have eval('max(d2-d1),0))?
>>
>>To force the field length to about 20 positions. Without that, you may end up having asterisks in your report
>>
>>
>>create cursor Test (d1 D, d2 D)
>>	
>>insert into test values(Date(), date()-1)
>>insert into test values(Date(), date()-2)
>>
>>insert into test values(Date(), date()+2)
>>insert into test values(Date(), date()+ 10002)
>>	
>>select mton(eval('max(ntom(d2-d1), $0)')) from test  && no asterisks
>>
>>select eval('max(ntom(d2-d1), 0)') from test  && asterisks on the last line
>>
>
>When I use the eval expression in the calculated field expression, the SFReports shows error SQL: Column 'AS' is not found.
>
>Thank you for your suggestion.

Sorry, I do not know the internals of SFReports. But my suspicion about the expr being fed into an SQL statement has been confirmed

I bet there's a way around.

Anyway. With the IIFs, try
iif( d2 - d1 < 0, 0000000000, d2 - d1 + 0000000000)
Gregory
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform