2

I want to run an automation for adding random value into data extension field.

I have data extension with name RecordsDe which having 3 field FieldA, FieldB & PKey.

Now i want to add random number value to PKey that will be unique for each row.

Any solution for this?

6

The naming of your fields suggests that PKey should be your primary key, which cannot be empty in the first place, if you set up the data extension correctly.

So therefore you need to either

  • add this functionality to the query that initially fills your data extension, or
  • set it as a default value in the data extension setup.

For the SQL solution you could use the NEWID-function:

SELECT
  NEWID() as PKey,
  FieldA,
  FieldB
FROM
  SourceDE

The data extension setup-version would be adding GUID() as default value for that field.

However, both solutions lead to IDs that aren't numerical, but rather IDs in GUID format (alphanumeric with dashes as separators).

Related documentation:

  • Thanks Markus Slabina, Actually i am updating RecordsDe from the other data extension using automation that required Primary key in target Data extension(RecordsDe). So i have added Pkey in as primary key in target data extension. So i want to add random value to it to make sure it will not be empty. – Front End Coder Aug 6 at 13:39
  • 1
    In that case the NEWID-solution should work for you. I added a code snippet for your reference. If my answer helped, please mark it as accepted, so others can easily see this has been resolved. – Markus Slabina Aug 6 at 15:15
  • Hi Markus, the code snippet you share worked like magic +100 Likes for that. I am new to MC if you share any reference guide for SQl Code that used for the most of the task in MC will help me in learning and other tasks. Thanks once again! – Front End Coder Aug 7 at 7:49
  • I already had SQL experience when I started with Marketing Cloud and I don't know of any specific resource for Marketing Cloud, but that isn't necessary in my opinion. Just search for SQL tutorials, as there are a lot of good ones out there (for the trickier functions Microsoft SQL ones, as this is used by Marketing Cloud). – Markus Slabina Aug 7 at 7:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.