Jump to content

Problem with a numerical SQL function


This topic is 4037 days old. Please don't post here. Open a new topic instead.

Recommended Posts

I successfully implemented a SQL function in my database thanks to Mr. Vodka, I tried to 'recycle' it to evaluate a numeric field but it doesn't work, what am I missing?

GetValue (

ExecuteSQL ( "
              SELECT
              Left(Position + '             ',12),
                  Count ( Position ) AS kount
              FROM HighScores
              GROUP BY Position
              ORDER BY kount DESC
             ";
              "     "; ""; ""
           )

            ; Get ( CalculationRepetitionNumber )
           )
Position is a numeric field, if I replace that field with another text field the function works just fine (it counts the instances and present me a top three).
Link to comment
Share on other sites

The Left(Position etc... works, it tells the function to put some spaces after the result and to take the first 12 characters; infact if I change the field to a non-numeric one it works just fine; anyways I tried to replace the line you mentioned with "Position," and it doesn't work anyways.

Link to comment
Share on other sites

The Left thing and the spaces are to tell SQL to display neatly the two 'columns'; anyways, even if I put simply the field name it does NOT work since 'Position' is a numeric field, do I need a different function to handle numbers and count like in the other instance you helped me solve?

GetValue (

ExecuteSQL ( "
              SELECT
              Position,
                  Count ( Position ) AS kount
              FROM HighScores
              GROUP BY Position
              ORDER BY kount DESC
             ";
              "     "; ""; ""
           )

            ; Get ( CalculationRepetitionNumber )
           )
Link to comment
Share on other sites

I'm very much SQL novice, but I downloaded the sample and tinkered...

 

POSITION is a reserved SQL keyword - rename your field. See the ODBC/JDBC docs

 

I really have to thank you for forcing me to learn this one!!

Link to comment
Share on other sites

I am a bit confused. Maybe I should put it in a script as you did to make it work? Because the result's given in a window and I'd want to get it in a field.

Link to comment
Share on other sites

If I use the same formula in a calculation field instead of returning the wanted result it gives me a "?", I believe I am missing something? The thing I fail to understand is that if I use a text field in the SQL formula it works just fine.

P.S. I Included an example of what I would like to achieve.

top3_countSample.zip

Link to comment
Share on other sites

You have a couple of things that are off:

 

1) there is a typo in the SQL statement: Count ( Positr )  --> remove the "r"

2) the field is set up to return a numeric value but the calc itself will return a text string --> change the field result to text

 

To guard against 1), where you use hard-coded field names and table names, use get(fieldname) and parse out the part that you need.  That embeds a real reference to the field.

  • Like 1
Link to comment
Share on other sites

This topic is 4037 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.