LIKE not working with @Variable comparison

  • PLEASE DISREGARD THIS POSTING - I HAD MY VARAIBLES SWITCHED...  SORRY! 

    I am not sure why this does not work (I have tried adding muliple wildcards and just comparing the system, but it still didn't work). 

    This is the basic code

    DELCARE @test-2 varchar(10),

                  @Sentence varchar(50)

    SELECT @test-2 = 'System',

                @test-2 = '%' + SUBSTRING( @test-2, 1, 4) + '%',

                @Sentence = 'This is a tes of the system'

     

    IF @test-2 LIKE @Sentence

         BEGIN

              PRINT 'Yes'

     

    I wasn't born stupid - I had to study.

  • DECLARE @test-2 varchar(10),

                  @Sentence varchar(50)

    SELECT @test-2 = 'System',

                @test-2 = '%' + SUBSTRING( @test-2, 1, 4) + '%',

                @Sentence = 'This is a tes of the system'

     

    IF @Sentence  like @test-2

         BEGIN

              PRINT 'Yes'

    end

    Glyndwr

  • It's more clear when written this way:

    DECLARE @test-2 varchar(10),

                  @Sentence varchar(50)

    SELECT @test-2 = 'System',

           @test-2 = SUBSTRING( @test-2, 1, 4),

           @Sentence = 'This is a tes of the system'

    IF @Sentence  like  + '%' + @test-2 + '%'

         BEGIN

              PRINT 'Yes'

    end

    Signature is NULL

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

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