How to execute SQL stored procedure from citect SCADA 2016?

Hello,

Is that possible to execute SQL stored procedure from citect SCADA's cicode and get an output?

If yes, please share the insight.

Store procedure has two inputs and single cell output.

  • Something like this?

    Before running - Setup an ODBC connection with the 32 Bit ODBC control panel to your SQL Server.
    C:\Windows\SysWOW64\odbcad32.exe
    This might have changed for newer Citect versions?

    //===========================================================================
    INT FUNCTION SQLStoredProcedure(STRING myParam)

    INT hSQL;
    INT statusSQL;
    STRING sSQLQuery = "";

    ErrSet(1);

    hSQL = SQLCreate("DSN = " + SQLServer + "; Uid = userName; Pwd = usersPassword;");

    IF hSQL <> -1 THEN
    StatusSQL = SQLOpen(hSQL);

    IF StatusSQL = 0 THEN

    //Get SQL Data
    sSQLQuery = "Exec MyStoredProcedureName @pParam1 = ^'" + myParam + "^'"
    StatusSQL = SQLExec(hSQL, sSQLQuery);

    IF (StatusSQL = 0) THEN
    WHILE SQLNext(hSQL) = 0 DO
    Do stuff...;
    END
    ELSE
    Prompt("SQL Fault - " + SQLErrMsg());
    END
    SQLClose(hSQL);
    ELSE
    Prompt("SQL Fault - " + SQLErrMsg());
    END
    ELSE
    Prompt("SQL Fault - " + SQLErrMsg());
    END

    SQLDispose(hSQL);

    ErrSet(0);

    RETURN 0;
    END