如何把其中的STRING换成随即的数值,而且随机数能控制一个范围
例如
COL001
------------------------------
0012008010106003707887204090
0012008010106481205201966090
0012008010107464207861626090
0012008010107474403140821090
0012008010106003707887204090
0012008010106481205201966090
0012008010107464207861626090
0012008010107474403140821090
0012008010107474614168049090
我要把 substring(COL001,12,4) 里面的4个字符---在里面的意义就是 代表时间
换成在 0820~0835之间的随即数字。
可以有部分重复,但是要随机,不知道SQL达人们有什么好的见解
[解决办法]
随即, 可以用算法实现不是随机么?就是由规律的换成在 0820~0835之间的数字。
[解决办法]
select '0'+ltrim(cast(rand()*16 as int)+820)
[解决办法]
select coloo1 from 表 where substring(coloo1,12,4) >='0820' and substring(coloo1,12,4) <='0835'
[解决办法]
create table tb(COL001 varchar(64)) insert tb select '0012008010106003707887204090' union all select '0012008010106481205201966090' union all select '0012008010107464207861626090' union all select '0012008010107474403140821090' union all select '0012008010106003707887204090' union all select '0012008010106481205201966090' union all select '0012008010107464207861626090' union all select '0012008010107474403140821090' union all select '0012008010107474614168049090' update tb set col001=stuff(COL001, 12, 4, right(10000+abs(checksum(newid()))%16+820, 4))select * from tb/*COL001----------------------------001200801010820370788720409000120080101083112052019660900012008010108244207861626090001200801010821440314082109000120080101082037078872040900012008010108351205201966090001200801010834420786162609000120080101083544031408210900012008010108264614168049090(9 row(s) affected)*/drop table tb