Generate 5 digit random numbers in SQL Server

Last Reply 8 months ago By dharmendr

Posted 8 months ago

hello,

i use this sql statement to generate random number 

 Select ABS(CAST(CAST(NEWID() AS VARBINARY) AS INT))/10000  as code

it works fine. some time it genrates 6 digit some times it generates 5 digit i want that it should always generate 5 digit please advice what change needed in this thanks

You are viewing reply posted by: dharmendr 8 months ago.
Posted 8 months ago

Hi nauna,

Refer below query.

SELECT CONVERT(NUMERIC(12,0),RAND() * 99999) + 10000 Code