Find a word from string

  • Hi All

    I would like to get rows wherever it has "restricted" . If I write condition with like '%restricted%' it is showing me all.

    create table #tbl_datafile_list (Autogrow varchar(500))
    go
    insert into #tbl_datafile_list values
    ('64.0 MB, unrestricted growth'),
    ('By 10 percent, restricted growth to 500000.0 MB'),
    ('By 10 percent, unrestricted growth'),
    ('1.0 MB, unrestricted growth'),
    ('0.0 MB, unrestricted growth'),
    ('256.0 MB, unrestricted growth'),
    ('128.0 MB, unrestricted growth'),
    ('64.0 MB, restricted growth to 2097152.0 MB'),
    ('64.0 MB, restricted growth to 500000.0 MB'),
    ('64.0 MB, restricted growth to 10240.0 MB')
    go
    select * from #tbl_datafile_list
  • SELECT * FROM #tbl_datafile_list WHERE Autogrow LIKE '% restricted %'

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

  • Thanks Phil,  good catch on the space. If there is no space I think it will be different function to use.

    • This reply was modified 1 year ago by  Saran.
  • Or, just in case there might be: '64.0 MB,restricted growth to 2097152.0 MB'

    SELECT * FROM #tbl_datafile_list WHERE Autogrow LIKE '%[^A-Za-z]restricted[^A-Za-z]%'

     

    SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".

  • Thank you ScottPletcher.

Viewing 5 posts - 1 through 4 (of 4 total)

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