• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 210
  • Last Modified:

SQL 2008 - Identify like data

Hi all,

I have two tables that i am performing left joins on.  My problem is that most of the data in the two fields i am trying to match on are the same, but there are some instances when the data is not exactly alike but similar.

For example

Table 1's field data:
1.5% 10
Cash Option
Net 45 days from INV

Table 2's field data:
1.5% 10
Cash Option
Net 45

The problem is that "Net 45" and "Net 45 days from INV" mean the same thing.

The query i am trying to write looks like the following:

Select *
from Table1 c
left outer join Table2 pt ON Table1 = c.id = pt.id
left outer join Table3 ar ON pt.discount = ar.Disc AND
pt.percent = ar.percent AND
pt.days = ar.days AND
pt.desc = ar.desc  ---My issue is here.  
Can i use a like clause or contain clause here because the SOME of the data does not match exactly, but most of it does?

Any suggestions on how to write this query?
  • 3
1 Solution
HainKurtSr. System AnalystCommented:
try like

pt.desc like ar.desc  + '%'

or other way

ar.desc like pt.desc + '%'
HainKurtSr. System AnalystCommented:
or use CharIndex

(CHARINDEX(ar.desc, pt.desc)>0 or CHARINDEX(pt.desc, ar.desc)>0)
HainKurtSr. System AnalystCommented:
I guess we need or in "like" too

( pt.desc like ar.desc  + '%' or ar.desc like pt.desc + '%')
MoreThanDoubledAuthor Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now