Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Executing Store Procedure (SP) in ASP

A stored procedure is a group of Transact-SQL statements compiled into a


single execution plan.
In a layman language a stored procedure is an already written SQL
statement that is saved in the database. If we find ourselves using the same
query over and over again, it would make sense to put it into a stored
procedure. When we put this SQL statement in a stored procedure, we can
then run the stored procedure from the database's command environment ,
using the exec command.
An example is:
CREATE PROCEDURE NameOfStoreProcedure
AS
SELECT FirstName, LastName FROM TableName;
GO
EXEC NameOfStoreProcedure
The name of the stored procedure is "NameOfStoreProcedure ", and "exec"
tells SQL Server to execute the code in the stored procedure.
There are two main advantages of using store procedure in our program

Because stored procedures are stored within the DBMS, bandwidth and
execution time are reduced. This is because a single stored procedure
can execute a complex set of SQL statements.

With Store procedure we will store our entire business login inside the
database itself. So if we plan to migrate from one technology to
another say from classic ASP to .NET then we only need to change the
user interface reset of the business logic remain same.
set con = Server.CreateObject("ADODB.Connection")
con.Open strConnect
Set Comm = Server.CreateObject("ADODB.Command")
comm.ActiveConnection = con
comm.CommandText = "sqlstoredprocedurename"
comm.CommandType = adCmdStoredProc
comm.Parameters.Append comm.CreateParameter("ID" ,
adVarchar,adParamInput, 50, id)
comm.Parameters.Append comm.CreateParameter("PRODUCT", adVarchar,

adParamInput,50, producttype )
comm.Parameters.Append comm.CreateParameter("ACCOUNT", adVarchar,
adParamInput,100, "" )
comm.Parameters.Append comm.CreateParameter("O_Errors", adVarchar,
adParamOutput,50) 'output parameters
comm.Execute

You might also like