locked
insert random value from predefined list of possible values RRS feed

  • Question

  • Hi all,

    My need is to insert random value from predefined list of possible values. It's data obfuscation project, thus no strict rules what value should be, rather it should be random. Each row should have its own value. When we are out of possible values (more rows comparing to amount of possible values) then values should be repeated.

    My guess is that I can just loop through list of possible values. But this is rather not random. How do I randomize the order?

    Please advise.

    Monday, April 6, 2020 5:10 PM

Answers

  • SELECT * FROM tbl ORDER BY newid() will give you rows in a random order.


    Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

    • Marked as answer by marchelloua Monday, April 6, 2020 10:46 PM
    Monday, April 6, 2020 9:49 PM