Thứ Tư, 7 tháng 10, 2015

Solution when Like sql does not work

Example, you have query using Like operation, everything seem to be good, but you can not receive any row even you have a row in table tbl_Article which have Title column = 'Thật hài hước quá' .

DECLARE @Keyword NVARCHAR(2000) = N'hài hước'

SELECT  *
FROM dbo.tbl_Article a
WHERE a.Title LIKE N'%' + @Keyword + '%'

This's happen because there is a newline at the end of the label, so 

this is solution:

SELECT  *
FROM dbo.tbl_Article a
WHERE REPLACE(REPLACE(a.Title, CHAR(10), ''), CHAR(13), '') LIKE N'%' + @Keyword + '%'

Or you can update Title column:

UPDATE [page] Set [label] = REPLACE(REPLACE([Title], CHAR(10), ''), CHAR(13), '')


Không có nhận xét nào:

Đăng nhận xét