SQL
CopyCode The Code is as follows: Create procedure proname // use create procedure to create a stored procedure proname as the stored procedure name
@ Lname varchar (30) // defines the input parameter
As
Set nocount on
Begin
Select * From tablename where lname like '%' + @ lname + '%' // use selece to fuzzy query all rows whose lname value is similar to the value of the input parameter lname
End
Go
A stored procedure with an input parameter has been created and a record set of all queries is returned.
The following describes how to use ASP to operate the stored procedure.Copy codeThe Code is as follows: // The following is a string that establishes a connection with MSSQL Server. As we all know, I will not talk about it.
Strconnect = "driver = {SQL Server}; server = (local); uid = sa; Password =; database = dataname"
Set conn = server. Createobject ("ADODB. Connection ")
Conn. Open strconnect
Set cmd = server. Createobject ("ADODB. Command") // create a command object
With cmd
Cmd. activeconnection = conn // Conn is the connection string
Cmd. commandtext = "proname" // The Name Of The stored procedure to be used.
Cmd. commandtype = 4 // The commandtype attribute indicates the request type.
//-1 indicates that the commandtext parameter type cannot be determined
// 1 indicates that commandtext is a common command type
// 2 indicates that the commandtext parameter is an existing table name.
// 4 indicates that the commandtext parameter is the name of a stored procedure, so commandtype = 4 here.
Cmd. Prepared = true // requires that the SQL command be compiled first
Cmd. Parameters. append cmd. createparameter ("@ lname", 4, lname) // Add the @ lname parameter. The lname following the parameter is the variable defined on the ASP page.
Set rs = cmd. Execute // set the RS variable to retrieve the returned query record set.
End
Do while not Rs. EOF // use do loop to read the rows in the RS record set
Response. Write (RS ("field name") "<br/> ")
Rs. movenext // move to the next
Loop // end Loop
Rs. Close // close the object