您的位置:首页 > 数据库

怎么使用T-sql生成两位字母

2009-08-03 16:51 246 查看
SQL codeselect char(cast(rand()*25 as int)+97)+char(cast(rand()*25
as int)+97)

select 两位随机字母 =
(select top 1 id from (select 'A' as id union select 'B' union select 'C' union select 'D' union select 'E' union select 'Z') m order by newid())
+
(select top 1 id from (select 'A' as id union select 'B' union select 'C' union select 'D' union select 'E' union select 'Z') n order by newid())

范围为0-1的之间的float数。

那么 * 25就得到 0 到 25之间的数。

0-25之间的数 + 97 就得到 97-122之间的数。

26个英文字母, a的ascii码是97

你要产生的大写的话,写 + 65 就可以了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: