I'm using VBScript to access SQL Server and the configuration is ok as it works when inserting new values and even when changing the columns names.
However, now I want to get the name of the columns and I'am able to get the first record, but not the second and the third.
The format of the SQL query results are output in a single column with three rows.
Here's the documentation but I cannot get anything clear:(.
My code:
Function getColumnNames(tableName)
Dim sql, rst
rst = "result1, result2, result3" 'resultX are string tags
sql = "SELECT name FROM sys.columns WHERE object_id = OBJECT_ID('" & "precios"& "') ORDER BY column_id ASC"
$DBExecute("sqlExpress", sql, rst)
MsgBox $result1
MsgBox $result2
MsgBox $result3
End Function
$result1 stores correctly the value while $result2 and $result3 are blank. I have tried several ways, as definining rst as:
rst = "result" 'result is a string array from 0 to 2
rst = "result(1), result(2), result(3)" 'result is a string array from 0 to 2
No one worked. Can anyone help me? Thanks.
NOTE: I'm working on Aveva Edge SCADA software, or Indusoft
I finally got this solution. It works. And yes, it is for Indusoft o Aveva Edge.
Function getColumnNames(tableName)
Dim sql, numCur, numRows, row, txt
sql ="Select name FROM sys.columns WHERE object_id = OBJECT_ID('" & tableName & "') ORDER BY column_id Asc"
numCur = $DBCursorOpenSQL("sqlExpress", sql)
numRows = $DBCursorRowCount(numCur)
For row=1 To numRows
$namesInDB[row-1] = $DBCursorGetValue(numCur,"name")
$DBCursorNext(numCur)
Next
$variablesInDB = numRows
$DBCursorClose(numCur)
End Function