Search code examples
sqlsql-server-2012full-text-search

SQL Server 2012 query string containing slash


I've looked all over the internet and stackoverflow for an answer to this question, but can't seem to find anything that answers it so here goes...

Is there anything special that needs to be done to a forward slash (/) for them to be included in search queries?

Scenario: I have a query that contains a string being searched for that includes a forward slash. The search term is a dimension of a particular item so it must contain the slash to indicate a fraction. I've tried escaping it with a backslash, but that doesn't work. The query is as follows:

SELECT * FROM ITEMDATA WHERE CONTAINS(dimensions, '3/8')

This query returns 0 results.

Example of data to be searched on:

•Pitch: 3/8" •Gauge: .050

I also need to get the double quote in the search phrase to specify units, but that's another problem.

Any suggestions?


Solution

  • If we need to search in sql table column with a particular string, we need to use LIKE command, so that we can use it like in various ways. 1. Returns results having dimensions column value contains the string 3/8

    'SELECT * FROM ITEMDATA WHERE dimensions LIKE '%3/8%';`
    
    1. Returns results having dimensions column value strictly starts with the string 3/8

    SELECT * FROM ITEMDATA WHERE dimensions LIKE '3/8%';

    1. Returns results having dimensions column value strictly ends with the string 3/8.

    SELECT * FROM ITEMDATA WHERE dimensions LIKE '3/8%';