Home Forums SQL Server 7,2000 SQL Server Newbies extracting column values when a part of the column value is known RE: extracting column values when a part of the column value is known<!-- 864 -->

  • Quick thought, use the LIKE operator

    😎

    USE tempdb;

    GO

    DECLARE @test-2 TABLE

    (

    TEST_ID INT IDENTITY(1,1) NOT NULL PRIMARY KEY CLUSTERED

    ,TEST_STRING VARCHAR(50) NOT NULL

    );

    INSERT INTO @test-2(TEST_STRING)

    VALUES

    ('I am a bad Gal')

    ,('I am a good Gal')

    ,('This is an old horse')

    ,('This is a good horse')

    ,('I am a good boy')

    ,('I am a naugthy boy');

    SELECT

    *

    FROM @test-2 T

    WHERE T.TEST_STRING LIKE '%good%';

    Results

    TEST_ID TEST_STRING

    ----------- ---------------------

    2 I am a good Gal

    4 This is a good horse

    5 I am a good boy