How to achieve "Full word match" value comes from source table column

  • create table #Source(Column_source varchar(20))

    Insert into #Source values('1'),('2')

    need to search full word match from #source table column column_source values 1 & 2 with #result table column Column_result

    create table #result(column_result varchar(20))

    Insert into #result values('223 1'),('122 2 11'),('323 22 1'),('133')

    If i join the above two tables i need result set like below, should match full word from source table column values which are 1 & 2

    : Results

    223 1

    122 2 11

    323 22 1

    need exact full word match result should be like below.. I'm not looking for LIKE operator

  • What's wrong with LIKE operator if it does exactly what you're asking for?

    SELECT *

    FROM #Source s

    JOIN #result r ON ' ' + r.column_result + ' ' LIKE '% ' + s.Column_source + ' %'

    Further explanation: http://www.sqlservercentral.com/articles/T-SQL/130558/

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • Luis Cazares (2/4/2016)


    What's wrong with LIKE operator if it does exactly what you're asking for?

    SELECT *

    FROM #Source s

    JOIN #result r ON ' ' + r.column_result + ' ' LIKE '% ' + s.Column_source + ' %'

    Further explanation: http://www.sqlservercentral.com/articles/T-SQL/130558/

    I does not pick the first value: '223 1'.

    Correction: It does, but only for a limited case of a single delimiter, blank space in this case.

    _____________
    Code for TallyGenerator

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

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