Reputation: 1
I am trying to create a custom view in excel for a pivot, I cant join the YEARSF because the tb1 format is 2016-17 and tb2 is 2016/17, how can i join these, see code below... what is the appropriate way of doing this
TB1.YEARF = TB2.YEARF
Seems to be the issue
SELECT TB1.YEARF,
TB1.MC,
TB1.CATEG,
TB1.ID,
TB1.TY,
TB1.CAT,
TB1.LOC,
TB2.HD0_NAME,
TB2.HD1_NAME,
TB2.HD2_NAME,
TB2.HD3_NAME,
TB2.HD4_NAME
FROM DB.TB2 TB2, DB.TB1 TB1
WHERE TB2.CAT = TB1.CAT AND TB2.LOC = TB1.LOC AND TB1.TY = TB2.TY AND TB1.YEARF = TB2.YEARF AND TB1.ID = TB2.ID
Upvotes: 0
Views: 69
Reputation: 108686
It happens that both Oracle and MySQL have REPLACE()
functions.
If you change the part of your query that reads
AND TB1.YEARF = TB2.YEARF AND
to
AND TB1.YEARF = REPLACE(TB2.YEARF, '/', '-') AND
you may be able to join these tables. It's not going to be fast.
In general, to do this kind of inexact matching, you have to
figure out the rules for matching. For example, if you want abcd/ef
to match abcd-ef
then you can use what I wrote above. If you want abcd/ef
to match abcd
, that's a different rule.
Write a SQL expression to implement your rules.
But, you know, step 1 must come before step 2.
If all you care about is matching the abcd
parts of abcd/ef
and abcd-ef
you can write a rule for that.
AND SUBSTR(TB1.YEARF, 1, 4) = SUBSTR(TB2.YEARF, 1, 4) AND
Upvotes: 1