matching columns

  • hello, can you help me please with a matching issue?

    i got 2 tables ([TA] and [TB]) and they have a column that should match ([TA].[C] with [TB].[C]). however, [TA].[C] may contain incomplete version of the items from [TB].[C].

    for example:

    [TA].[C] has 'asdf' and 'abcd'

    the selection should contain all items from [TB] where [TB].[C] starts with 'asdf' or 'abcd'.

    we should get such matchings from [TB].[C]: 'asdf', 'asdf 1', 'abcdxyz'

    best regards

  • Pleas fallow the URL at my signature to see how to post questions. See the code and the remarks in the code for an answer for your question.

    --Creating the table

    create table TA (c varchar(20))

    go

    create table TB (c varchar(20))

    go

    --Insert test data

    insert into TA (c)

    select 'asdf'

    union

    select 'abcd'

    go

    insert into TB(c)

    select 'asdf'

    union

    select 'asdf 1'

    union

    select 'abcdxyz'

    union

    select 'Should not return'

    go

    --running the select query. Joning that table with the like

    --operator and adding a wild card at the end of TA.c

    select TA.c, TB.c

    from TA inner join TB on TB.c like TA.c+'%'

    go

    --Clean up

    drop table TA

    go

    drop table TB

    go

    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/

  • thank you very much!

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

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