Updated: Jan 5, 2022
This blog will give a T-SQL script o create and use Six Digit One Time Password using the SQL Server RAND function.
The RAND function in SQL Server returns a random decimal value. We can run the following script for generating the SIX digits random value that can act as an OTP.
SELECT RIGHT(CAST(RAND()*1000000000+999999 AS INT),6) as OTP
Multiple executions of script generates random 6 digit value as shown below.


