0

I have the following Id for my table:

SELECT CONCAT('TPR-', DATE_FORMAT(NOW(), '%Y-%m-%d-%h-%m-%s')) AS Id;

At the End, I want to add a random number start from 01-99. How can I achieve this?

I tried the following syntax, but I want to add leading zero if the number is start from 1 - 9.

FLOOR( 1 + RAND( ) * 99 )

Need advice please.

underscore_d
  • 6,309
  • 3
  • 38
  • 64
Haminteu
  • 1,292
  • 4
  • 23
  • 49

1 Answers1

1

Just use the LPAD function: LPAD( FLOOR( 1 + RAND( ) * 99 ), 2, '0')

https://www.w3resource.com/mysql/string-functions/mysql-lpad-function.php

rafwell
  • 429
  • 1
  • 4
  • 12