0

I am trying to randomly assign names within a set list of names to phone calls in SQL. For example,

 Date    |Customer Number| Consultant Name 
 2/24/18 |193-245-6445   | Jill
 2/15/18 |123-456-4663   | Amy
Samantha
  • 91
  • 2
  • 7
  • You need to get the "universe of names" from somewhere. Do you have an extra table where they are? – The Impaler Mar 27 '19 at 18:09
  • yes it would be in a table – Samantha Mar 27 '19 at 18:11
  • 3
    Add the table with the names to the question. An example table with few names will do. Also, random functionality is heavily dependent on the specific database. Which database are you using? Oracle, PostgreSQL, Sybase, etc. – The Impaler Mar 27 '19 at 18:16
  • Is your question simply how to select a random row from the table of names you have? You might want to look at https://stackoverflow.com/questions/9868409/how-to-get-records-randomly-from-the-oracle-database for Oracle or https://stackoverflow.com/questions/52964/sql-server-random-sort for SQL Server – EdmCoff Mar 27 '19 at 18:18

1 Answers1

0

Agree with The Impaler, You need to provide more information. Assuming that it is Oracle and you have two tables you need to join. You may hypothetically

select table1.Date, table1.Customer_Number, table2.Consultant_Name
from <Table 1> table1
left join (select rownum as rownumout, tb2.* 
           from <Table 2> tb2) table2
on 1 = 1 
where table2.rownumout = floor(dbms_random.value(1, 100));

Assuming you have 100 names in table 2. If more than increase the range.

Nik
  • 371
  • 4
  • 15