Need SQL to identify "ending" string of characters

  • Column DataType

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

    COL_A  varchar(254) NULL

    Need SQL to check for last characters of COL_A = 'ING'    For example, in this list:

    COL_A

    -----

    Housing

    Housing Availability

    Zoning

    Taxing Liability

    I'd want the following rows returned:

    Housing

    Zoning

    Any suggestions for a T-SQL statement to do this?

    thx in advance

    BT
  • select * from table

    where LOWER(RIGHT(RTRIM(COL_A),3)) = 'ing'

    --RTRIM to eliminate any trailing blanks

    --LOWER to take care of case issues

    Or simpler:

    select * from table

    where COL_A LIKE '%ing'

    Test for efficiency, but the upper one will probably be better.

     

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_fa-fz_7oqb.asp

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

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