我想要使用IF else如果內聯表中的邏輯值爲SQL函數並返回基於該邏輯的containsstable。但我遇到IF IF塊的語法問題。謝謝您的幫助。因爲我不能參數化Contaststable中的列,我不得不訴諸使用if else語句。這是代碼。謝謝。幫助! - SQL - 如果其他IF邏輯返回Containstable選擇
我越來越
消息156,級別15,狀態1,過程FullTextSearch 17行 關鍵字 'IF' 附近有語法錯誤。
ALTER FUNCTION [dbo].[FullTextSearch]
(
@Columns nvarchar(100), @SearchPhrase nvarchar(100)
)
RETURNS TABLE
AS
RETURN
IF (@Columns='Title')
BEGIN
SELECT *
from projects as P inner join
containstable(PROJECTS, Title, @SearchPhrase) as K
on P.project_id = K.[KEY]
END
ELSE IF (@Columns='Project_Details')
BEGIN
SELECT *
from projects as P inner join
containstable(PROJECTS, Project_Details, @SearchPhrase) as K
on P.project_id = K.[KEY]
END
ELSE IF (@Columns='Contact_Info')
BEGIN
SELECT *
from projects as P inner join
containstable(PROJECTS, Contact_Info, @SearchPhrase) as K
on P.project_id = K.[KEY]
END
ELSE IF (@Columns='Project_Description')
BEGIN
SELECT *
from projects as P inner join
containstable(PROJECTS, Project_Description, @SearchPhrase) as K
on P.project_id = K.[KEY]
END
ELSE -- (@Columns='All')
BEGIN
SELECT *
from projects as P inner join
containstable(PROJECTS, (Title, Project_Details, Contact_Info, Project_Description), @SearchPhrase) as K
on P.project_id = K.[KEY]
END
我只是想知道你到底在用這個查詢來做什麼。 – 2009-02-25 19:29:30
我在C#上用asp.net的LinqTOSQL層有一個搜索接口,問題是,LINQ to SQL很好,但它不支持全文搜索功能,所以除了過程或使用表值函數以外,沒有辦法。我讀過關於使用包裝/擴展,但決定這一點。 – stevenjmyu 2009-02-25 19:32:25
因此您正在嘗試在字段內搜索字符串。你知道它可能在哪些領域,或者它們可能都是潛在的嗎? – 2009-02-25 19:38:26