方法1:你可以给参数一定 默认值
create proc SelectAllProcess
@xingming varchar(15)='',
@chenghu varchar(15)='',
@haoma varchar(15)='',
@fenzu varchar(10)=''
。。。
exec SelectAllProcess
@xingming=default,
@chenghu= default,
@haoma=default,
@fenzu=default
或者用
if exists(select * from sysobjects where name = 'SelectAllProcess' )
drop Proc SelectAllProcess
go
create proc SelectAllProcess
@xingming varchar(15),
@chenghu varchar(15),
@haoma varchar(15),
@fenzu varchar(10)
as
begin
select xingming as 姓名,xingbie as 性别,chenghu as 称呼,haoma as 号码,fenzu as 分组,shijian as 时间
from MemoTable
where xingming like '%'+COALESCE(@xingming,'')+'%' or
chenghu like '%'+COALESCE(@chenghu,'')+'%' or
haoma like '%'+COALESCE(@haoma,'')+'%' or
fenzu like '%'+COALESCE(@fenzu,'')+'%'
end
exec SelectAllProcess @xingming='盼',@chenghu=null,@haoma='13720686947',@fenzu=null
ALTER
PROCEDURE
[dbo].[pro_Search_keys]
@keys
nvarchar(max)
AS
BEGIN
SELECT*
FROM
text_Text
where
Title
like
‘%’+@keys+‘%’
END
ISNULL(@fenzu,'') 每一个参数加上这个函数 就没有问题了
你的存储过程写的有问题。
你应该判断一下如果参数为空就不参加查询。