Home Page for the TeradataForum
 

Archives of the TeradataForum

Message Posted: Fri, 04 Mar 2005 @ 10:54:31 GMT


     
  <Prev Next>   <<First <Prev Next> Last>>  


Subj:   Re: Random function with a column value
 
From:   Abdul Wahab

Hi,

For your query u can give like that:

     Select STORE_COUNT, Random(1,5) from Table_Name;

The RANDOM function may be used to generate a random number between a specified range.

RANDOM (Lower limit, Upper limit) returns a random number between the lower and upper limits inclusive. Both limits must be specified, otherwise a random number between 0 and approximately 4 billion is generated.

Consider the department table, which consists of nine rows.

     SELECT department_number FROM department;

     department_number
     -----------------
     501
     301
     201
     600
     100
     402
     403
     302
     401

Example:

Assign a random number between 1 and 9 to each department.

     SELECT department_number, RANDOM(1,9) FROM department;

     department_number      Random(1,9)
     -----------------      -----------
                 501                  2
                 301                  6
                 201                  3
                 600                  7
                 100                  3
                 402                  2
                 403                  1
                 302                  5
                 401                  1

Note it is possible for random numbers to repeat. The RANDOM function is activated for each row processed, thus duplicate random values are possible.


Regards,

Abdul Wahab.



     
  <Prev Next>   <<First <Prev Next> Last>>  
 
 
 
 
 
 
 
 
  
  Top Home Privacy Feedback  
 
 
Copyright for the TeradataForum (TDATA-L), Manta BlueSky    
Copyright 2016 - All Rights Reserved    
Last Modified: 15 Jun 2023