WakaChewbacca WakaChewbacca - 1 year ago 64
SQL Question

Passing a SQL result as an argument for a VBScript object

I am working on an extant .Asp program at the moment which contains the following snippet:

Dim strRel_Report_Location
Dim rs, sql, blnReportExists
Dim strUID
Dim intMonth, intYear

sql = "Select NewID() AS UID"
Set rs = DB.Execute(Sql)
strUID = rs("UID")

strRel_Report_Location = "/Admin/Reports/Temp/t" & strUID & ".html"

My question is, how is it possible to pass the string "UID" as an argument to the object 'rs'? One may easily divine from the code that the intent is to pass the resulting "NewID()" call to the path which is assigned in the statement:

strRel_Report_Location = "/Admin/Reports/Temp/t" & strUID & ".html"

Any illumination would be greatly appreciated as I don't wish to just make assumptions on the code with which I am working.

I'm sure this is a layup for you guys, but thank you for your help!

Answer Source

I have to make an assumption here because you never show how the DB variable is created. I am going to assume you are working with straight ADO because the call signatures in your code match that.

Again, you are probably working with an Ado Command instance which has the method Execute. This method takes a sql string, executes it on the database server, and then returns a Recordset which contains the results of the query that executed. The recordset has an indexer with the name of the columns, using that indexer you can get the value in the column.

If you want to learn more about this code it would help to start reading up on how to work with ADO.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download