IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[order_179_1_search]') AND type = 'P')
DROP PROCEDURE [dbo].[order_179_1_search]
GO

-- 生成时间:2018-05-03 16:29:26 by ebs-core  
create  procedure order_179_1_search(
@ordid bigint,
@key nvarchar(200),
@pagesize int 
) 
as  
begin  
set nocount on 
-- 将@key 分解为三个值
declare @key1 nvarchar(200)
declare @key2 nvarchar(200)
declare @key3 nvarchar(200)
set @key1=''
set @key2=''
set @key3=''
declare @i int 
set @key1 = @key 
set @key1 = replace(@key1,'  ',' ') 
set @key1 = replace(@key1,'  ',' ') 
set @key1 = replace(@key1,'  ',' ') 
set @key1 = replace(@key1,',,',',') 
set @key1 = replace(@key1,',,',',') 
set @key1 = replace(@key1,',,',',') 
set @key1 = replace(@key1,',',' ') 
set @key1 = replace(@key1,'  ',' ') 
set @key1 = replace(@key1,'  ',' ') 
set @i = charindex(' ',@key1) 
if (@i>0) 
begin
set @key2 = substring(@key1,@i+1,200) 
set @key1 = substring(@key1,1,@i-1) 
end 
if (@key2>'') 
begin
set @i = charindex(' ',@key2) 
if (@i>0) 
begin
set @key3 = substring(@key2,@i+1,200) 
set @key2 = substring(@key2,1,@i-1) 
end 
end 
if (@key1='') set @key1='%' 
if (charindex('%',@key1)<=0) set @key1='%'+@key1+'%'

if (@key2='') set @key2='%' 
if (charindex('%',@key2)<=0) set @key2='%'+@key2+'%'

if (@key3='') set @key3='%' 
if (charindex('%',@key3)<=0) set @key3='%'+@key3+'%'

select top(@pagesize) * from order_179_1  
where ord2_ordid=@ordid and ( (1=1) ) order by ord2_order, ord2_id 
select ord2_id  as ord2id_page from order_179_1 
where ord2_ordid=@ordid and ( (1=1) ) order by ord2_order, ord2_id 

set nocount off
end