Lauren
Lauren

Reputation: 65

Joining a table on string of text

Can someone help me with the following. I am trying to create a join on two tables

wbr_global.gl_ap_details gad and decipher.manual_utr_er_te_miscodings muetm

I am trying to joining the column sub _sub category in decipher.manual_utr_er_te_miscodings muetm to gad.line_description. The issue is I want it to join is the string of text in decipher.manual_utr_er_te_miscodings muetm is found at all in gad.line_description. This is because I am classifying a GL category based on if a set of text is found in the larger GL line description. For example is the line description contains the text "Gasoline" then it would be categorized to "Car Rental". I pasted what I have below.

Select
gad.account_number ,
gad.line_description,
from wbr_global.gl_ap_details gad
left join decipher.manual_utr_er_te_miscodings muetm on gad.account_number =     muetm.current_account_number 

I am not sure if I would be able to use the following to help solve.

left join decipher.manual_utr_er_te_miscodings muetm on FIND_IN_SET(muetm.sub_sub_category ,gad.line_description )

Here is a picture of the decipher.manual_utr_er_te_miscodings muetm table. enter image description here

Upvotes: 0

Views: 965

Answers (1)

Neon Tetra
Neon Tetra

Reputation: 159

One way would be to do the join on a LIKE operator:

   SELECT gad.account_number,
          gad.line_description
     FROM wbr_global.gl_ap_details gad
LEFT JOIN decipher.manual_utr_er_te_miscodings muetm 
       ON gad.line_description LIKE '%' + muetm.sub_sub_category + '%'

Upvotes: 1

Related Questions