У меня новое условие WHERE, когда @Keyword объявляется из процедуры Store.но когда я попробовал синтаксис CASE, у меня появляется ошибка «Неверный синтаксис рядом с ключевым словом« LIKE ».»
Я пробовал этот синтаксис CASE в PostgreSQL, но без ошибки.
ALTER PROCEDURE [dbo].[ACC_SEARCH_INVOICE_DATEX]
@projectID varchar(3),
@FromDate DATETIME,
@Todate DATETIME ,
@Filter varchar(50),
@Keyword varchar(50),
@posted int,
@status integer,
@source varchar(50)
AS
SELECT posted, InvoiceHead.InvoiceID, InvoiceHead.Date AS date, InvoiceHead.UserID, InvoiceHead.CreditTerm, InvoiceHead.DueDate, InvoiceHead.CustomerID,
Party.Name, InvoiceHead.Total, InvoiceHead.Currency, InvoiceHead.Rate, Subtotal, Discount, Tax, Commision, Bonus, Total, DownPayment, Balance ,
substring(InvoiceID,4,LEN(invoiceid)-11-3) Source, selling, technician, Lock , InvoiceHead.Status
FROM InvoiceHead LEFT OUTER JOIN Party ON InvoiceHead.CustomerID = Party.PartyID
WHERE
CASE
WHEN @Keyword = 'SCP'
THEN ((InvoiceHead.InvoiceID LIKE '%' + @Keyword + '%') or (InvoiceHead.InvoiceID LIKE '%SCJ%'))
WHEN @Keyword = 'SCNH'
THEN ((InvoiceHead.InvoiceID LIKE '%' + @Keyword + '%') or (InvoiceHead.InvoiceID LIKE '%SNJH%'))
WHEN @Keyword = 'SCNHL'
THEN ((InvoiceHead.InvoiceID LIKE '%' + @Keyword + '%') or (InvoiceHead.InvoiceID LIKE '%SNJHL%'))
ELSE ((InvoiceHead.InvoiceID LIKE '%' + @Keyword + '%'))
END
ORDER BY InvoiceHead.InvoiceID