I need to create a string of random digits in TSQL
I thought about HASH + CONVERT
But convert works on style - so I am not show how can I do it if data type of result and expression are both char(100) for example
Any advices?
4 Answers
SET the @Length to what you need. Add more copies of sys.objects as necessary.
DECLARE @Length INT
SET @Length = 10000
DECLARE @RandomDigits VARCHAR(MAX)
SET @RandomDigits = ''
SELECT TOP (@Length) @RandomDigits = @RandomDigits + RIGHT(CHECKSUM(NEWID()), 1)
FROM sys.objects a, sys.objects b, sys.objects c
SELECT @RandomDigits