Search code examples
sql-serversql-like

SQL Server LIKE containing bracket characters(Variable)


How can I search in a letter in variable like this 🔽

Where Name Like '%@Variable%'

Solution

  • Hello @ahmad_lababidi welcome to stackoverflow,

    If it is not an ASCII character and generally requires a column of type NVARCHAR and a literal with string N '' (Except when the encoding accepts symbols)

    for example, the UNICODE code of your character is 55357, so you can search for this character in your query, as in the following example.

    CREATE TABLE #FIND (NAME nvarchar(10));
    INSERT INTO #FIND VALUES (N'🔽');
    
    SELECT UNICODE(N'🔽')   --> 55357
    
    SELECT *
    FROM #FIND
    WHERE NAME LIKE '%' + NCHAR(55357) + '%'