原文地址:http://www.cnblogs.com/hoojo/archive/2011/07/19/2110862.html
例子存储过程代码:
create proc proc_Select
(
@id varchar(20),
@name varchar(20),
@sex char(4)
)
as
if(@id='' and @name='' and @sex='')
select * from tb_Employee
else
begin
if(@id<>'')
select * from tb_Employee where ID=@id
else if(@name<>'')
select * from tb_Employee where Name like @name
else
select * from tb_Employee where Sex=@sex
end
GO
create proc proc_Insert
(
@id varchar(20),
@name varchar(20),
@sex char(4),
@age int,
@tel varchar(20),
@address varchar(100)
)
as
if exists(select * from tb_Employee where ID=@id)
return 0
else
begin
insert into tb_Employee(ID,Name,Sex,Age,Tel,Address)value(@id,@name,@sex,@age,@tel,@address)
return 1
end
GO