KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Passing 4D variable to external SQL server
PRODUCT: 4D | VERSION: 14.0 | PLATFORM: Mac & Win
Published On: March 7, 2014

A common practice to pass a 4D variable to an external sql server is to use the command SQL EXECUTE. Passing 4D variables to an external SQL server from a Begin SQL/End SQL may not always work depending on which server you are working with. A good way to do this is to first concatenate the variables into a text variable, and then pass the text variable into SQL EXECUTE.

Here is an example of inserting 4D variables ($var1, $var2) into a table (Table_1) on the external sql database.

C_TEXT($smt;$var1;$var2)
$var1:="var1"
$var2:="var2"

SQL LOGIN("ODBC:DSN";"username";"password123")
If (ok=1)
  $smt:="Insert Into Table_1 Values (:$var1, :$var2)"
  SQL EXECUTE($smt)
End if
SQL LOGOUT