Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Matching fields on a combination of characters

Status
Not open for further replies.

t16turbo

Programmer
Mar 22, 2005
315
GB
Hi,

I need to link two tables on one field.
The problem is, the value (project_no) exists in a different format on each table.

Table 1: D00151DAA
Table 2: D00151-A

I need to link the tables by looking for a match
where the first 6 characters are the same, and the 8th character.

does anyone know a fancy way of doing this?

 
[tt]WHERE Substr(tab1.col1,1,6) = Substr(tab2.col1,1,6)
AND Substr(tab1.col1,8,1) = Substr(tab2.col1,8,1);[/tt]

Note that this is likely to prevent indexes from being used on either table.
 
T16,

Try this code:
Code:
select <expression-list>
from table_1 a, table_2 b
where substr(a.project_no,1,6)||substr(a.project_no,8,1) =
      substr(b.project_no,1,6)||substr(b.project_no,8,1)
/
Let us know if this resolves your need.

[santa]Mufasa
(aka Dave of Sandy, Utah, USA)

Do you use Oracle and live or work in Utah, USA?
Then click here to join Utah Oracle Users Group on Tek-Tips.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top