top of page
Writer's picturerajendra gupta

T-SQL Script to generate Six Digit One Time Password (OTP)

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.

SQL Server RAND function

T-SQL Script to generate Six Digit One Time Password (OTP)

Generate Random values

1 Comment


Unknown member
Sep 11, 2023

Programming and learning are two very important aspects of modern life that can be interconnected and mutually influencing. Programming is important in various fields such as website development, mobile application development, scientific research nurse writers artificial intelligence, data analysis and many more.

Like
bottom of page