select char(cast(rand()*25 as int)+97)+char(cast(rand()*25 as int)+97)

解决方案 »

  1.   

    --自己补充C到Y
    select 两位随机字母 = 
    (select top 1 id from (select 'A' as id union select 'B' union select 'Z') m order by newid())
    +
    (select top 1 id from (select 'A' as id union select 'B' union select 'Z') n order by newid())/*
    两位随机字母
    ------
    BA(1 行受影响)
    */
      

  2.   

    --自己补充F到Y
    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())/*
    两位随机字母
    ------
    BA(1 行受影响)两位随机字母
    ------
    ED(1 行受影响)两位随机字母
    ------
    CB(1 行受影响).......
    */
      

  3.   


    rand返回0-1之间随机的float.
    即返回结果为0,0.xxx,1范围为0-1的之间的float数。那么 * 25就得到 0 到 25之间的数。0-25之间的数 + 97 就得到 97-122之间的数。26个英文字母, a的ascii码是97
    你要产生的大写的话,写 + 65 就可以了。
      

  4.   

    select char(65+ceiling(rand()*25))+char(97+ceiling(rand()*25))