Please help to resolve issue in SQL Query

  • I have table with content as below:

    IDName Description

    1Name_A des_kakà

    2Name_B des_kaka

    3Name_C des_kaká

    4Name_D des_amazon

    I want search description with keyword: 'kaka' and I want result

    IDName Description

    1Name_A des_kakà

    2Name_B des_kaka

    3Name_C des_kaká

    Please help to resolve above issue.

    Thank you very much

  • Hey,

    What collation are you using?

    If you want the query to be accent insensitive, you might have you use a collation hint on your comparison:

    eg:

    SELECT *

    FROM Venue

    WHERE

    Name COLLATE Latin1_general_CI_AI Like '%cafe%' COLLATE Latin1_general_CI_AI

  • Can you just use like function?

    Select * from table

    where description like 'des_kak%'

  • Then you're searching for a specific pattern.. what if the accent if on other characters?

    By matching accents in the collation hint, the data will be compared correctly and accurately and will cater for all variations.

  • Lip turner (11/19/2015)


    Can you just use like function?

    Select * from table

    where description like 'des_kak%'

    Always test:

    DROP TABLE #SampleData

    SELECT *

    INTO #SampleData

    FROM (VALUES

    (1, 'Name_A', CAST('des_kakà' AS NVARCHAR(20))),

    (2, 'Name_B', CAST('des_kaka' AS NVARCHAR(20))),

    (3, 'Name_C', CAST('des_kaká' AS NVARCHAR(20))),

    (4, 'Name_D', CAST('des_amazon' AS NVARCHAR(20)))

    ) d (ID, Name, [Description])

    DECLARE @Keyword NVARCHAR(20) = '%kaka%'

    SELECT *

    FROM #SampleData

    WHERE [Description] COLLATE Latin1_general_CI_AI LIKE @Keyword COLLATE Latin1_general_CI_AI

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden

  • Thank you very much,

    I did successful

  • ChrisM@Work (11/19/2015)


    Always test:

    +1000

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Sorry guys, I totally forget about that. Now I understand better. Thank you, all 🙂

Viewing 8 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply