這裏是一個動態查詢,會做什麼你想。
declare @search nvarchar(max)
declare @dyn_sql nvarchar(max)
declare @where nvarchar(max)
set @search = 'car 1000 london'
set @search = rtrim(LTRIM(@search))
set @search = REPLACE(@search,' ',',')
set @where = ''
while (LEN(@search) > 0)
begin
declare @place_holder nvarchar(100)
if((select CHARINDEX(',',@search)) = 0)
begin
set @place_holder = @search
end
else
begin
set @place_holder = SUBSTRING(@search, 0, CHARINDEX(',',@search))
end
set @place_holder = REPLACE(@place_holder,',','')
if((select CHARINDEX(',',@search)) = 0)
begin
set @search = ''
end
set @search = SUBSTRING(@search, CHARINDEX(',',@search)+1, LEN(@search))
set @where = @where+'name like ''%'[email protected]_holder+'%'' or '
set @where = @where+'description like ''%'[email protected]_holder+'%'' or '
set @where = @where+'location like ''%'[email protected]_holder+'%'' or '+CHAR(10)
end
set @where = SUBSTRING(@where,0,len(@where)-3)
set @dyn_sql =
'
select
*
from
Products
where
'[email protected]
exec (@dyn_sql)
那只是爲搜索條件 –
而且他是在說存在不翻譯爲LIKE「%標準%」,而是變成完全匹配的。 –
我想清楚一點。如果一個**描述**包含「這是一輛好車」,那麼這個記錄應該被提取用於** car **關鍵字 – Awan