I've been given a string that can contain multiple offer codes separated by a tilde 123~125~126
I also have a table that may or may not define a parent/child relationship
tbl_allowed
============
offercode varchar(15)
parent_oc varchar(15)
ex:
offercode = 124
parent_oc = 126
I already have a function that will take the delimited string and split it, but I want to take the string, compare the contents to what's in tbl_allowed
and regenerate it by replacing any values that exist in tbl_allowed
in the parent_oc column with the value in the offercode column. If no defined relationship exists, then just use itself.
this is pretty simple with a single offercode:
set @newOfferCode = (select top 1 coalesce(cac.offercode, @lOfferCode)
from tbl_allowed cac
where OfferCode = @lOfferCode or parent_oc = @lOfferCode)
select coalesce(nullif(@newOfferCode,''), @lOfferCode)
but I'm having difficulty when I have a tilde delimited string. Any ideas?