Compare two fields to see if one field's value is Contained in the other field

  • I've drawn a blank. I want to compare fielda and fieldb and find cases where the value of fieldb is part of the value in fielda.

  • you mean like a substring?

    declare @sample table(col1 varchar(10),Col2 varchar(30) )

    insert into @sample

    select '.com' ,'www.whatever.com' union

    select '.net','www.whatever.com' union

    select '.net','www.whatever.net'

    --charindex [string to find], [column or value to find to test]

    select * from @sample where charindex(col1,col2) > 0

    resutls:

    col1 Col2

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

    .com http://www.whatever.com

    .net http://www.whatever.net

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Kind of a DUH! moment for me. Thanks. This is exaclty what I needed.

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

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