S t o r e d P r o c e d u r e的标准写法:
Create Procedure Procedure_Name
Define Parameter
A s
SQL Structure
上面的语法结构中, P r o c e d u r e _ N a m e为存储结构的的名字,也是你将在C o m m a n d中引用的
名字。然后是定义输出和输入的参数。最后是一个S Q L结构化语句。下面是一个S t o r e d P r o c e d u r e
的例子,它无需输入参数,也没有输出。
Create Procedure Del_User
A s
Delect From Employee Where Job_ID=1
如果我们要删除指定的J o b _ I D,则我们需要给这个S t o r e d P r o c e d u r e输入参数。
Create Procedure Del_User1
@intID int
A s
Delect From Employee Where Job_Id = @intID
这里的@ i n t J o b就是一个输入参数,它可以从外部接受输入的值,下面是给它输入的a s p程
序:
Set conn=Server.CreateObject("ADODB.Connection")
Set comm=Server.CreateObject("ADODB.Command")
conn.ConnectionString="Driver={SQL Server};Server=ser;"&_
" u i d = s a ; p s s s = ; d a t a b a s e = e m p l o y e e "
c o n n . o p e n
Co m m . A c t i v e C o n n e c t i o n = c o n n
Co m m . C o m m a n d T y p e = a d C m d S t o r e d P r o c
Comm.CommandType="Del_User1" ' 这里的名字就是前面定义过的S t o r e d P r o c e d u r e的名字。
'下面就是参数的输入
p a r a m = c o m m . C r e a t e P a r a m e t e r ( " I D " , a d I n t , a d P a r a m I n p u t , 4 )
'这里的a d P a r a m I n p u t定义是最重要的。
Param.Value=1 ' 这里的值可以输入你想要的值,也可以用R e q u e s t来获得
Comm.Parameters.Append param
Comm.Execute
这样我们就可以向S t o r e d P r o c e d u r e传递参数了。
你的我不太懂问题,
如果你写
select ... from ... where ... 如果比较复杂的话。
可以写一个存储过程代替
create proc xxxx
as
select .... from ... where...
r然后把原来的查询语句换成存储过程名字就可以了。存储过程可以带参数的。
(Access数据库)在相应数据库文件中定义查询myfind:
select comid,comname,comaddr,comwanted
from cominfo
where comwanted like '*' &strearch& '*'
在asp页缅中写:
mcomd.commandtext="findcom"
set recjg=mcomd.createparamter("strearch",200,1,40,comselect)