Declare @keyWords nvarchar(1000)
Set @keyWords= '联想|lenovo|NOKIA|诺基亚 '
Declare @condition nvarchar(2000)
Declare @keyWord nvarchar(100)
while len(@keyWords)> 0
BEGIN
if(charIndex( '| ',@keyWords)> 0)
BEGIN
set @keyWord=substring(@keyWords,0,charIndex( '| ',@keyWords))
set @keyWords=substring(@keyWords,charIndex( '| ',@keyWords)+1,len(@keyWords)-charIndex( '| ',@keyWords))
END
ELSE
BEGIN
set @[email protected]
set @keyWords= ' '
END
set @[email protected] + ' OR ([Name] LIKE ' '% '[email protected]+ '% ' ') ';
--
END
PRINT @condition
[email protected]
如果这样写set @condition= ' OR ([Name] LIKE ' '% '[email protected]+ '% ' ') ';就正常
------解决方案--------------------
set @[email protected] + ' OR ([Name] LIKE % ' ' '[email protected]+ ' ' '% '
------解决方案--------------------
Declare @condition nvarchar(2000)
set @condition = ' '--不加就为null