创建随机数字T-SQL字符串 [英] Create random string of digits T-SQL
本文介绍了创建随机数字T-SQL字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在TSQL
中创建一串随机数字我想过 HASH
+ CONVERT
但是转换工作风格 - 所以我不显示如果数据类型的结果和表达式都是字符(100)例如
任何建议?
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?
推荐答案
将@Length设置为你所需要的。根据需要添加更多的sys.objects副本。
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
这篇关于创建随机数字T-SQL字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文