Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

SQL - Calculating income per quarter

Featured Replies

Hi all

I am trying to utilize ExecuteSQL to calculate earnings per quarter last year, however it doesn't appear to be working and I'm sitting here scratching my head.

Table JOB LINES - where each check is entered and the check issue date.
Table JOB TRACKING - contains portal for JOB LINES where data for each tax year, including checks and the quarterly earnings fields.

Other calculation fields are able to reference each table accordingly and return accurate results for each tax year.

Let ( [

sqlQuery = "SELECT Sum (Chk_GROSS)
FROM \"JOB LINES\"
WHERE paymentFlag IS NULL 
AND
Chk_DATE BETWEEN ? AND ? 
AND
Form IN («FORMS») " ;

FORMS = Substitute ( JOB TRACKING::Quarter_Tax_Form ; ¶ ; "," )

] ;

Case ( 

ExecuteSQL ( 
Substitute ( sqlQuery ; "«FORMS»" ; JOB TRACKING::Quarter_Tax_Form ) ; "" ; "" ; 
JOB TRACKING::Quarter1Start ; JOB TRACKING::Quarter1End )  = "?" ; "" ; 

ExecuteSQL ( 
Substitute ( sqlQuery ; "«FORMS»" ; JOB TRACKING::Quarter_Tax_Form ) ; "" ; "" ; 
JOB TRACKING::Quarter1Start ; JOB TRACKING::Quarter1End )

)
)

Quarter1Start and Quarter1End contain the quarter dates, i.e. Jan 1 to March 31.
JOBTRACKING::Quarter_Tax_Form contains checkboxes from a value list to "filter" the particular tax form, i.e. W2, 1099, etc.

I realize I'm missing the link between the two tables (JOB LINES::YEARid = JOBTRACKING::PrimaryKey). I've tried including this and I'm still getting the same error (see below) so I'm trying to eliminate calculation steps to see where the error is coming from.

There is an error in the syntax of the query.

If I select a tax form (in this case "W2") in the checkbox set I get the following:

The column named "W2" does not exist in any table in the column reference's scope.

If the tax form I select includes a numerical form, such as 1099, I get the following:

An expression contains data types that cannot be compared.

Perhaps a more experienced user can see where I'm going wrong here.

Thanks so much.

This is very difficult to follow. I would suggest you reduce the query to the minimum and then add clauses and conditions one by one until you get an error. Then you will know what to focus on.

AFAICT, the last 2 error messages you describe are caused by data type mismatch. If the Form field is a Text field, then the values listed in the IN operator must be surrounded by single quotes - e.g.

Form IN ('W2', '1099')

(And of course any quotes and single quotes that might exist in the values themselves must be escaped.)

 

1 hour ago, madman411 said:

I am trying to utilize ExecuteSQL to calculate earnings per quarter last year,

Wouldn't it be simpler to produce a report summarized by quarter? Then you would get all 4 quarters at once. From what I see, you are actually trying to sum the earnings of the first quarter only. Even for that, a filtered portal might be a better suited alternative.

 

Create an account or sign in to comment

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.