I have to generate 12 digit number(bigint) in sql server 2008 R2 itsleft. i have used these methods which i found on the internet
convert(numeric(12,0),rand() * 999999999999)
and
RIGHT(CAST(CAST(NEWID() AS VARBINARY(36)) AS BIGINT), 12)
while these do work the problem is sometimes the generated number has leading zeroes and that is stripped resulting in a 10 or 11 digit number.
Is there a consistent way to generate x digit numbers in sql?
Thanks. this is very urgent.
One solution is to just make sure it’s in the 12 digit range.