October 22, 2024
Chicago 12, Melborne City, USA
SQL

Unable to get SELECT SQL query result in VBScript


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, numRows, row, colName, 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.



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video