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

Hi, I just started using this function, it's very helpful.

 

I have a calculation that returns some transactions for this year.

 

 
ExecuteSQL ( "SELECT n_transactionAmountGross , t_transactionModel , t_FirstName frmt  FROM Transactions  WHERE  FamilyID_CustomerID = ?  AND c_transDate_frmt = 2013  " ; " : " ; "" ; FamilyID )
)
I'd like to substitute the current year for the hardcoded year by using a variable, however this doesn't work.
Let ( [   _yr = GetAsNumber (Year(Get(CurrentDate))  ) ] ; 

ExecuteSQL ( "SELECT n_transactionAmountGross , t_transactionModel , t_FirstName frmt  FROM Transactions  WHERE  FamilyID_CustomerID = ?  AND c_transDate_frmt = _yr  " ; " : " ; "" ; FamilyID )
)
What simple thing am I missing here?
 
 
 
Edit:
 
came across the pinned topic that speaks to tables with underscores in the name and tried the suggestion from there to no avail . . . as well as just removing the underscore from the variable name, and also then trying to quote the variable. 
 
Let ( [   _yr = GetAsNumber (Year(Get(CurrentDate))  ) ] ; 

ExecuteSQL ( "SELECT n_transactionAmountGross , t_transactionModel , t_FirstName frmt  FROM Transactions  WHERE  FamilyID_CustomerID = ?  AND c_transDate_frmt = "  & Quote("_yr")  &   "" ;    " : "   ;   ""     ;    FamilyID )
)
 
Thanks,
jim

Solved by jimlongo

Go to solution

Add the name of the variable to the parameter list, then inside the SQL statement refer to it with the ? placeholder; FM will resolve the variable and insert the value into the SQL, like it does with the reference to the FamilyID field. Here's a pretty-printed version:

 

Let (

myYear = Year ( Get ( CurrentDate ) ) ;

 

ExecuteSQL

( "

SELECT n_transactionAmountGross , t_transactionModel , "t_FirstName frmt"  // there's a blank in the field name

FROM Transactions

WHERE

  FamilyID_CustomerID = ? AND

  c_transDate_frmt = ?

;    " : "   ;   ""  ;

FamilyID ; myYear

)

 

)

 

  • Author
  • Solution

Thanks for that eos, putting it as a parameter worked.

 

Just to note, the underscore still causes a problem, and enclosing the field name with the space breaks it.  Here's what eventually worked for me.

Let (  
	yr =  Year(Get(CurrentDate)) ; 

ExecuteSQL (" 
	SELECT n_transactionAmountGross , t_transactionModel , t_LastName frmt 
	FROM Transactions  
	WHERE  FamilyID_CustomerID = ?  AND c_transDate_frmt = ? 
        "   ;    " : "   ;   ""  ;  FamilyID; yr  )

)

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.