0

I have the code below setup as an Automation in Marketing Cloud.

  • B.Subscriber_Key is a nullable column.
  • A.SUBSCRIBER_KEY is not a nullable column.

I only want B.Subscriber_Key to be updated with the value from A.SUBSCRIBER_KEY and that is working, but I keep getting an error in the end that says "Cannot insert a NULL value into a non-nullable column". It doesn't specify the column or value in question. How can I fix this?

SELECT B.EMAIL, 
CASE WHEN B.SUBSCRIBER_KEY IS null THEN A.SUBSCRIBER_KEY
ELSE B.Subscriber_Key
END AS SUBSCRIBER_KEY
FROM ent.main_subscriber A
LEFT JOIN ent.newsletter B
ON A.EMAIL = B.EMAIL

1 Answer 1

1

It could be that Subscriber_Key is not always populated in the newsletter DE.

You can handle that with the coalesce function and a check in the where-clause:

SELECT 
B.EMAIL
, coalesce(b.SubscriberKey, a.subscriber_key) AS SUBSCRIBER_KEY
FROM ent.main_subscriber A
LEFT JOIN ent.newsletter B ON A.EMAIL = B.EMAIL
where coalesce(b.SubscriberKey, a.subscriber_key) is not null
and b.email is not null

Coalesce just means "give me the first non-null value in this list of comma-separated of fields".

2
  • I think this did it. Thank you!
    – Michelle
    Feb 28, 2023 at 18:13
  • If this answer has solved your question please consider accepting it by clicking the check-mark on the left. Accepted answers indicate to the community that you've found a solution (and it increases the reputation of both of us). Feb 28, 2023 at 18:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .