Join 2 tables on string up to space

  • Does anyone have an easy way to do this:

    Table 1 has string 'FENWAY CT' while Table 2 has just 'FENWAY' or 'FENWAY COURT'. I want to join the 2 tables on just the string up to the space i.e. tbl1 'FENWAY' = tbl2 'FENWAY'

    I think CHARINDEX may be a start but can't figure out how I'd use it in a 20K record table join

    Thanks!

     

  • substring(tbl1.field1, 1, patindex('% %',tbl1.field1) - 1) = substring(tbl2.field1, 1, patindex('% %',tbl2.field1) -1)

     

  • Thanks Lynn - worked beautifully!

     

     

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

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