CREATE PROCEDURE sp_employ
AS
select ID,Name,Picture,Time,Duty from employ
Go
而SQL语句:
select ID,Name,Picture,Time,Duty from employ where ID=10230
对应的存储过程是:(用Alter替换我们已有的存储过程)
ALTER PROCEDURE sp_employ
@inID int
AS
select ID,Name,Picture,Time,Duty from employ where ID=@inID
Go
下面对比一下SQL和存储过程在ASP中的情况。首先看看直接执行SQL的情况:
<%
dim Conn, strSQL, rs
set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "DSN=webData;uid=user;pwd=password"
strSQL = " select ID,Name,Picture,Time,Duty from employ "
Set rs = Conn.Execute(strSQL)
%>
再看看如何执行Stored Procedure:
<%
dim Conn, strSQL, rs
set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "DSN=webData;uid=user;pwd=password" ’make connection
strSQL = "sp_employ"
Set rs = Conn.Execute(strSQL)
%>
而执行带参数的Stored Procedure也是相当类似的:
<%
dim Conn, strSQL, rs, myInt
myInt = 1
set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "DSN=webData;uid=user;pwd=password"
strSQL = "sp_myStoredProcedure " & myInt
Set rs = Conn.Execute(strSQL)
%>
你可能觉得在ASP中使用存储过程原来是这样的简单。对!就是这么简单。