Search code examples
sql-server-2008like-keyword

sql server like clause


Hey guys, I have a column in an sql server table that is nvarchar(max). I query the table with:

select * from CrossArticle_Article where Summary like '%PHILADELPHIA-BASED GUITARIST AND composer Tim%'

If I enter 5 words in the like clause, I get a result, if I add more words, I dont get any results, even if the record exists. Is there any limitation for the records?


Solution

  • There's no limitation. I suspect the LIKE clause is behaving properly, but your data is the cause of you not getting the results you're expecting.

    Can you post some data to help illustrate those records that you expect in your resultset?

    declare @foo table (title Nvarchar(MAX))
    INSERT INTO @foo (title) 
    values ('South PHILADELPHIA-BASED GUITARIST AND composer Tim X'),
    ('North PHILADELPHIA-BASED GUITARIST AND composer Timofei'),
    ('In West-PHILADELPHIA-BASED GUITARIST AND composer Timothy Born and raised'),
    ('PHILADELPHIA-BASED GUITARIST AND composer Timmy Smith'),
    ('<p>PHILADELPHIA-BASED GUITARIST AND composer Tim Motzer finds infinite joy in diversity. His output as a leader and sideman crisscrosses multiple musical universes, including jazz, fusion, prog, hip-hop, soul, electronica, and the avantgarde.')
    
    -- results in 5, as expected
    select count(*) from @foo 
    where title like '%PHILADELPHIA-BASED GUITARIST AND composer Tim%' 
    
    -- results in 1, as expected
    select count(*) from @foo 
    where title like '%PHILADELPHIA-BASED GUITARIST AND composer Timmy S%'