--查询的存储过程
create procedure test
@订购号 varchar(100)
,@维修站号 varchar(100)
,@维修站名称 varchar(100)
,@生成日期 datetime
,@是否结算 bit
as
declare @tj varchar(8000)
select @tj='',@tj=@tj
+case isnull(@订购号,'') when '' then ''
else ' and [订购号]='''+@订购号+'''' end
+case isnull(@维修站号,'') when '' then ''
else ' and [维修站号]='''+@维修站号+'''' end
+case isnull(@维修站名称,'') when '' then ''
else ' and [维修站名称]='''+@维修站名称+'''' end
+case isnull(@生成日期,'') when '' then ''
else ' and [生成日期]='''+@生成日期+'''' end
+' and [是否结算]='+cast(isnull(@是否结算,0) as varchar)
if @tj<>''
set @tj=' where '+right(@tj,len(@tj)-5)
declare @订购号 varchar(100),@维修站号 varchar(100),@维修站名称 varchar(100),@生成日期 datetime
select * from tableName where
订购号 like case when isnull(@订购号,0)='0' then '%' else 订购号 end,
and 维修站号 like case when isnull(@维修站号,0)='0' then '%' else 维修站号 end,
and 维修站名称 like case when isnull(@维修站名称,0)='0' then '%' else 维修站名称 end,
and 生成日期 like case when isnull(@生成日期,0)='0' then '%' else 生成日期 end
select * from tableName where
订购号 like case when isnull(@订购号,0)='0' then '%' else 订购号 end,
and 维修站号 like case when isnull(@维修站号,0)='0' then '%' else 维修站号 end,
and 维修站名称 like case when isnull(@维修站名称,0)='0' then '%' else 维修站名称 end,
and 生成日期 like case when isnull(@生成日期,0)='0' then '%' else 生成日期 end