search string that does not contain a string

  • declare @test-2 varchar(1000)

    set @test-2 = 'alksjdfhkalsdhf update a;slkfjdlakjsdf where sadlkfjak!sdlfj people_table asdjfadsf'

    select case when @test-2 like '%update%[^where]%people_table%' then 1 else 0 end

    I want to check the string and then return true, if I can find where in the string between update and table and false if you dont find where between update and table. Is that possible?

    Pramod

  • try this

    declare @test-2 varchar(1000)

    declare @rez int

    set @test-2 = 'alksjdfhkalsdhf update a;slkfjdlakjsdf where sadlkfjak!sdlfj people_table asdjfadsf'

    if ( charindex('update',substring( @test-2, 0, charindex('where',@test,0) )) > 0 and ( charindex('table',substring( @test-2, charindex('where',@test,0), len(@test)) ) ) )

    set @rez = 1

    else

    set @rez = 0

  • One more way:

    declare @test-2 varchar(1000)

    set @test-2 = 'alksjdfhkalsdhf update a;slkfjdlakjsdf where sadlkfjak!sdlfj people_table asdjfadsf'

    Select case when @test-2 like '%update%people_table%' and @test-2 not like '%update%where%people_table%' then 1 else 0 end

    Adi

    --------------------------------------------------------------
    To know how to ask questions and increase the chances of getting asnwers:
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    For better answers on performance questions, click on the following...
    http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

Viewing 3 posts - 1 through 2 (of 2 total)

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