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.

Featured Replies

Working on a nested SQL that I think should work, but is giving me wrong data:
 
ExecuteSQL ( 
"SELECT COUNT (DISTINCT pgc1."C1FD~Date")
FROM "PGC1~Field Days" pgc1
WHERE pgc1."C1FD~Date" BETWEEN ? AND ?
AND pgc1."C1FD~Primary" IN (
'Height Pole'
)
"
"" ; "" ;
ScheduledTimeOff::q1StartDate ; ScheduledTimeOff::q1EndDate ; 
ScheduledTimeOff::id_EmployeeNumber )
 
gives me 42
 
ExecuteSQL ( 
"SELECT r.workingDaysSQLList
FROM "@Resources" r
" ; 
"" ; ""  )
 
gives me this:
 
Flatbed,Escort,Tillerman,Height Pole,Assem/Disassem,Route Survey,Push Truck,Pull Truck,Load/Unload,Care/Maintenance (In-Field),Off-Duty (In-Field),Repositioning/Travel,Mentoring,Supervision,Training (In-Field),Training (In-Classroom),Shop/Office Work
 
Note, Height Pole is 3rd in list
 
ExecuteSQL ( 
"SELECT COUNT (DISTINCT pgc1."C1FD~Date")
FROM "PGC1~Field Days" pgc1
WHERE pgc1."C1FD~Date" BETWEEN ? AND ?
AND pgc1."C1FD~Primary" IN (
SELECT r.workingDaysSQLList
FROM "@Resources" r
)
"
"" ; "" ;
ScheduledTimeOff::q1StartDate ; ScheduledTimeOff::q1EndDate ; 
ScheduledTimeOff::id_EmployeeNumber )
 
gives me 0
 
what's wrong with my nested select? it should work.

Solved by Mark Geerdes

Go to solution

just answered your question on Technet...

 

I think the issue is that the result of the 2nd ExecuteSQL is jus a string of values and the IN clause expects each text value to be surrounded in single quotes.

  • Author

I had tried to put single quotes into another field, and then doing the nested select to get to that list, but still came up with 0. In trying to work around this issue, I came up with this:

 

ExecuteSQL ( 
"SELECT COUNT (DISTINCT "C1FD~Date")
FROM "PGC1~Field Days"
WHERE "C1FD~Date" BETWEEN ? AND ?
AND "C1FD~Primary" IN ( " & STO » Resources::workingDaysSQLList & " )
AND "C1FD~EMPNo" = ?
"
"" ; "" ;
ScheduledTimeOff::q1StartDate ; ScheduledTimeOff::q1EndDate ; 
ScheduledTimeOff::id_EmployeeNumber )
 
This works, but I would still like any ideas on why the nested SELECT didn't work if anyone has any ideas.
  • Author
  • Solution

okay, fixed the issue. I thought I had tried this once before posting here, but maybe my syntax was wrong. The trick is to make sure you are selecting from multiple records, not one large pre-formatted list in a single field. If you run the nested select on it's own, you should get a return delimited list instead of a comma separated list. Here is the statement that works for anyone else trying to figure this out:

 

 

ExecuteSQL ( 
"SELECT COUNT (DISTINCT "C1FD~Date")
FROM "PGC1~Field Days"
WHERE "C1FD~Date" BETWEEN ? AND ?
AND "C1FD~Primary" IN ( 
SELECT workingDays FROM "@WorkingDayList"
 )
AND "C1FD~EMPNo" = ?
"
"" ; "" ;
ScheduledTimeOff::q1StartDate ; ScheduledTimeOff::q1EndDate ; 
ScheduledTimeOff::id_EmployeeNumber )

I noticed you are using BETWEEN. You might might want to test using date >= and date<= instead. I have found this to be much, much faster than BETWEEN, although it might not be noticeable if you're querying a smaller range to begin with.

Create an account or sign in to comment

Similar Content

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.