Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

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

Recommended Posts

Posted

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
Posted

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

)

 

)

 

  • Like 2
Posted

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  )

)

This topic is 4134 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.