Link to home
Start Free TrialLog in
Avatar of Nigel_Taylor
Nigel_Taylor

asked on

Execute stored procedure from VBScript

Hi guys,

As you can see from the code attached I am currenlty creating a connection to a SQL Server DB and then executing two SQL statements 1 to insert some data and the other to return. This is the proof of concept and is working well.

I now want to move the code into stored procedures as the SQL needs to be rolled out to many scripts and I want to centrally manage the code. I have created the stored procedures with the input parameters and they work fine.

How do I now change the code below to execute the stored procedures attaching the parameters?

Any help will be greatfully recieved.
Str_Connect = "Provider=SQLOLEDB;Data Source=srv02\sqlexpress;Initial Catalog=IPPbxDynamic"
Set CnnSQL=CreateObject("ADODB.Connection")
CnnSQL.Open Str_Connect,"***", "*****"
 
If CnnSQL.State=1 Then	'** Check if the connection is alive
 
'********
'  Insert the current call into the DB
'********
 
  strInsertSQL = "Insert INTO tblDynamicCallDetails (CallId, ScriptName) VALUES ('123','456')"	' ** Build the dynamic SQL Statement
  CnnSQL.Execute(strInsertSQL)
 
'********
'  Insert the current call into the DB
'********
 
  strReturnSQL = "Select * from tblDynamicCallDetails"	' ** Build the dynamic SQL Statement
 
  Set Rs=CreateObject("ADODB.Recordset")
  Set Rs=CnnSQL.Execute(strSQL)
  Do while not Rs.EOF
	'write the responses back to variables
	Rs.MoveNext
  Loop
 
  Rs.Close
  Set Rs = Nothing
 
else
  'Msgbox "Not Connected"
End If
 
cnnSQL.Close
Set cnnSQL = Nothing

Open in new window

SOLUTION
Avatar of Kyle Abrahams, PMP
Kyle Abrahams, PMP
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Nigel_Taylor
Nigel_Taylor

ASKER

Thanks guys for the solutions. That has been a great help.