So your Query Activity failed. What next?

SFMC Support can certainly tell you exactly what the error was, and now you can (sometimes) see some error details in the Activity tab of Automation Studio.

Here are a few things that I’ve found are common things that cause Query Activities to fail.

Primary key violation

If your query results in duplicate rows not allowed by the primary key, then you’ll need to change your primary key or de-duplicate the rows that result from your query. Here’s my go-to method for deduplication. The innermost query sorts by insertDate, groups by subscriber key and assigns a ranking to each row. The outermost query selects only the oldest result per subscriber key.

See the gist on github.

Inserting a null value into a non-nullable field

If you have fields in your target Data Extension that are non-nullable, you need to ensure none of the columns in your query return a null value. You can utilize the isnull() SQL function to handle that situation:

See the gist on github.

Inserting a value too long for the field (truncation)

If any of your source data extension columns are larger than the target, then you can adjust the length of the target column or use the left() SQL function to trim the value:

See the gist on github.

Timeout

Probably the most frustrating error is the the 30 minute timeout. If your query won’t run in that amount of time, then it’ll error out. There are a bunch of different ways to address query timeouts. Here are some tips:

  1. First and foremost, you need to reduce the number of row you’re querying. This can be altering your date range or adding additional criteria to target rows more specifically.
  2. Leverage the primary keys for speed.  While we don’t have any insight in to the indexes that SFMC behind the scenes, it’s a good bet the primary keys are indexes.  So the more utilize their values in the where-clause, the better.
  3. Don’t join multiple System Data Views in your query.  It’s a pain, but it’s a good practice to have a separate query for each activity (sends, opens, clicks, etc.).  Last resort is to make your own copies of the System Data Views with primary keys and refresh them on an interval.  The data extension versions will perform better.
  4. Make sure your where-clause conditionals are sargable to reduce the number of type-conversions and to optimize the selection:

See the gist on github.

  1. If it’s still timing out, leave a comment below with some details. I have some other tricks to share.

Target Data Extension has been deleted

Easy fix for this one. Just re-select the target data extension in your Query Definition.

Mis-match data types

You can’t, for example, insert a string value of $12.34 into a Decimal field. What I typically do in this scenario is to check the data types of the source data extension(s) and ensure that they match the target data extension column data types. If they don’t, then I’ll either recreate the target column with the correct data type or cast/convert/fix the source column value in the query.

Share
Published by
Adam Spriggs @wvpv

Recent Posts

  • fun

Wanna box?

Wanna box for those, Sir? Nah, I hate violence. Is it cool if I just pay with my card?

1 month ago
  • fun
  • inspiration

I’ll have what he’s having, part 12

https://www.youtube.com/watch?v=vC8gJ0_9o4M South Pole trekker Aleksander Gamme revisiting a stash he left for himself a month earlier. Be sure and turn…

2 months ago
  • technology & science

Chevy big block 396 rebuild

https://www.youtube.com/watch?v=z5U5Kxrv6SY Good stuff from Hagerty's #RedlineRebuild series.

2 months ago
  • sports

Giannis for MVP

3 months ago
  • fun
  • technology & science

Artificial Intelligence

3 months ago