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

create proc mps_g_search_key_ctid_1 @cc_createtime_min datetime, @cc_createtime_max datetime,@cc_code_min varchar(50), @cc_code_max varchar(50) as begin  
if @cc_code_min>'' 
begin 
if charindex('%',@cc_code_min) = 0
begin
set @cc_code_min = '%'+@cc_code_min+'%';
end
end 
if @cc_code_max>'' 
begin 
if charindex('%',@cc_code_max) = 0
begin
set@cc_code_max = '%'+@cc_code_max+'%';
end
end  select * from mps_customer where (cc_createtime>=@cc_createtime_min or @cc_createtime_min = '') and (cc_createtime<=(@cc_createtime_max +' 23:59:59') or @cc_createtime_max = '') and  (cc_code like @cc_code_min or @cc_code_min = '') and (cc_code like @cc_code_max or @cc_code_max = '') end