存储过程like问题
create proc Report_GetPN
@brand varchar(50)='',
@productline varchar(50) = '',
@keyword varchar(50) =''
as
declare @sql varchar(max)
set @sql='select m01_brand,m01_bu_code,m01_prod_family,m01_item_no from Dealer.dbo.mstock '
set @sql = @sql + ' where 1=1'
if(LEN(@brand) >0)
set @sql = @sql+' and m01_brand =''' +@brand +''''
if(LEN(@productline) >0)
set @sql = @sql +' and m01_bu_code = ''' + @productline + ''''
if(LEN(@keyword) >0)
set @sql = @sql + ' and m01_prod_family like ''' + @keyword + '%'+ ''''
我想在@sql = @sql + ' and m01_prod_family like ''' + @keyword + '%'+ '''' 用两个like语句模糊查询,该怎么写呢?
------解决方案--------------------create proc Report_GetPN
@brand varchar(50)='',
@productline varchar(50) = '',
@keyword varchar(50) =''
as
declare @sql varchar(max)
set @sql='select m01_brand,m01_bu_code,m01_prod_family,m01_item_no from Dealer.dbo.mstock '
set @sql = @sql + ' where 1=1'
if(LEN(@brand) >0)
set @sql = @sql+' and m01_brand =''' +@brand +''''
if(LEN(@productline) >0)
set @sql = @sql +' and m01_bu_code = ''' + @productline + ''''
if(LEN(@keyword) >0)
set @sql = @sql + ' and m01_prod_family like ''' + @keyword + '%'+ '''' + ' and xx like ''' + @keyword + '%'+ ''''