-- ============================================= -- Author: luokuan -- Create date: 2010-08-04 -- Description: 根据用户选择的商品信息类型 审核状态 关键字查询信息 -- ============================================= ALTER PROCEDURE [dbo].[Pro_GetProductInfoByKeyWord] ( @categoryid varchar(10), @status varchar(10), @keyword varchar(50) ) as begin declare @str varchar(500) set @str='select * from tg_teams' set @str=@str+' where' --当商品类型编号为空 并且商品审核状态为空 关键不为空时 在所有商品信息中根据关键字查询商品信息 if((@categoryid is null)and(@status is null)and(@keyword is not null)) begin set @str=@str+' title like ''%'+@keyword+'%'' or description like ''%'+@keyword+'%'' ' print @str exec(@str) end --当商品类型条件不为空 关键字不为空时 根据商品类型名称 和关键字查询商品信息 else if((@categoryid is not null) and(@keyword is not null) and (@status is null)) begin set @str=@str+' category_id='+@categoryid+' and title like ''%'+@keyword+'%'' or description like ''%'+@keyword+'%''' print @str end --如果商品类型不为空 并且商品审核状态不为空 关键字不为空 时根据商品审核状态 商品类型编号 关键字 查询商品信息 else if((@categoryid is not null) and (@status is not null) and (@keyword is not null)) begin set @str=@str+' category_id='+@categoryid+' and statue='+@status+' and title like ''%'+@keyword+'%'' or description like ''%'+@keyword+'%'' ' print @str end --当商品审核状态条件 并且 关键字不为空时 根据商品审核状态和关键字查询商品信息 else if((@status is not null) and (@keyword is not null) and (@categoryid is null)) begin set @str=@str+' statue='+@status+' and title like ''%'+@keyword+'%'' or description like ''%'+@keyword+'%'' ' print @str end exec (@str) end