I’m having a problem with the SqLite printf element, which I need to use to format part of the result in an SqLite query.
My code is:
var rs as RowSet = app.db.SelectSQL("
SELECT person.id, person.name, person.surname, person.age, sum(Invoices.amount)
FROM invoices
INNER JOIN person on person.id = invoices.customer
GROUP by person.surname
ORDER by " + Sortby)
I’ve split the query into separate lines to aid readability. It is one line in the original
Sortby is a variable containing one of the fieldnames, to determine the sort order. The rowset is displayed in a 5 column listbox.
This code works fine, but if I change ’ sum(Invoices.amount) ’ to ’ printf("%.2f", sum(Invoices.amount)) ’ I get errors, the first of which is that there is a syntax error in this line of code. I need to do this so that I can haver the sum of Invoices figure formatted to 2 places of decimals.
I have used DB Browser for SqLite to test the query, and it works fine with ’ printf("%.2f",sum(Invoices.amount)) ’ & formats the output as it should.
Is there some other way of formatting output in this situation?
Many thanks for any ideas!