I need to insert random data in my database for testing, and would need to generate a numeric string (can start with 0) 27 characters long.
I've been looking into NEWID() but it contains also letters, same for NEWSEQUENTIALID().
So far my approach would be to make a while loop, generate each digit randomly and concatenate it, but it seems to be a very slow approach.
I am using MSSQL 2014.
TALLYtable with the required number of digits andSTRING_AGG()itselect right(replicate('0', 27) + convert(decimal(38, 0), 0x26000001 + crypt_gen_random(13)), 27). This approach cannot generate arbitrarily long values, but it's likely to be faster than anything else (where such things matter).