Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to return COUNT(*) and store it in a Variable for further usage in VBscript

I am new to Vbscript (3 days to be precise),

I am connecting my script to SQL Server and playing around with databases. I have connected successfully

Now here's what I want to do:

I want to store the value of SELECT COUNT(*) FROM TABLE_A in a variable to be used in VBscript.

This SQL query returns the number of rows in table and it is an integer, but how do I return it and save in a variable?

I tried this:

Dim VARX
SET VARX = connection.execute("SELECT COUNT(*) FROM TABLE_A")

So now VARX should contain the number of rows of TABLE_A.

But this is a wrong way I know. And of course It posts an error "TYPE Mismatch:". Please guide me!

like image 270
Anant Vaibhav Avatar asked Dec 19 '25 20:12

Anant Vaibhav


1 Answers

Try something like this :

Dim rs, varx
SET rs = connection.execute("SELECT COUNT(*) FROM TABLE_A")
varx = rs(0).value

Not my field of expertise actually, here are some references :

  • http://www.tek-tips.com/viewthread.cfm?qid=1632757
  • VBScript - Retrieving a Scalar Value From a Stored Procedure on SQL Server 2008
like image 141
har07 Avatar answered Dec 21 '25 10:12

har07