2012-10-26 28 views
0

我在SQL 檢索使用用戶變量字符查詢如下其中使用可變

DECLARE @search 
SET @search='chicken' 

SELECT * from Recipes where TITLE like '@search' 

這是正確的一個小問題陳述?它應該檢索標題包含給予@search的單詞的食譜。

我甚至試過給

SELECT * from Recipes where TITLE IN ('[email protected]+') 
SELECT * from Recipes where TITLE [email protected] 
SELECT * from Recipes where TITLE =$[@search] 

但似乎沒有工作。

在此先感謝

回答

0

試試這個

set @search='chicken' 

select * from recipes where title like '%' + @search + '%' 
0

假設你正在使用SQL Server因爲未定查詢,連接具有%變量所以你會得到標題包含關鍵字您搜索

DECLARE @search 
SET @search='chicken' 

SELECT * from Recipes where TITLE like '%' + @search + '%'