Applies To:
  • CitectSCADA 5.xx

Summary:
How do I use the AS (Alias) keyword in the Cicode SQLGetField() statement? 

Solution:
The Citect SQLGetField() function does not support any alias names as defined by the AS command. However if a column has no name, f.e. if the contents were calculated, or if a column has an alias name, then I can use the name "fieldX" to identify that column. X is then replaced with the column number.

Example

(using the Northwind demo database in SQL Server 7):

FUNCTION
TestSql()

int hdev, i;

hdev = sqlconnect("dsn=testsql")

       sqlexec(hdev,"select orderid, productid,
    unitprice*(1-discount)*quantity as [ordersize] from
    [order details] order by [ordersize] desc");
    sqlnext(hdev);

         for i = 1 to 5 do
            tagwrite("orderid" + inttostr(i),
              sqlgetfield(hdev,"orderid"));
            tagwrite("productid" + inttostr(i),
              sqlgetfield(hdev,"productid"));
            tagwrite("ordersize" + inttostr(i),
              StrToInt(sqlgetfield(hdev,"field3")));
            sqlnext(hdev);
      end;

       sqlend(hdev);
    sqldisconnect(hdev);
end

In this example the third column in my result record set (as returned by the SqlExec() statement), is a calculated column with an alias name. So I will have to use "field3" to get the contents of a field in that column with the SQLGetField() function.

 

Keywords:
 

Attachments