将就用下先,最好建立个符号表(永久的)
declare @t table (a varchar(1))insert @t 
select '0'
union all
select '1'
union all
select '2'
union all
select '3'
union all
select '4'
union all
select '5'
union all
select '6'
union all
select '7'
union all
select '8'
union all
select '9'
union all
select 'A'
union all
select 'B'
union all
select 'C'
union all
select 'D'
union all
select 'E'
union all
select 'F'
union all
select 'G'
union all
select 'H'
union all
select 'I'
union all
select 'J'
union all
select 'K'
union all
select 'L'
union all
select 'M'
union all
select 'N'
union all
select 'O'
union all
select 'P'
union all
select 'Q'
union all
select 'R'
union all
select 'S'
union all
select 'T'
union all
select 'U'
union all
select 'V'
union all
select 'W'
union all
select 'X'
union all
select 'Y'
union all
select 'Z'declare @r varchar(20)
declare @i int
set @r=''
set @i=1
while @i<=12
begin
select top 1
       @r=@r+a
from @t
order by newid()
set @i=@i+1
end
print @r

解决方案 »

  1.   

    declare @t table (a varchar(1))insert @t 
    select '0'
    union all
    select '1'
    union all
    select '2'
    union all
    select '3'
    union all
    select '4'
    union all
    select '5'
    union all
    select '6'
    union all
    select '7'
    union all
    select '8'
    union all
    select '9'
    union all
    select 'A'
    union all
    select 'B'
    union all
    select 'C'
    union all
    select 'D'
    union all
    select 'E'
    union all
    select 'F'
    union all
    select 'G'
    union all
    select 'H'
    union all
    select 'I'
    union all
    select 'J'
    union all
    select 'K'
    union all
    select 'L'
    union all
    select 'M'
    union all
    select 'N'
    union all
    select 'O'
    union all
    select 'P'
    union all
    select 'Q'
    union all
    select 'R'
    union all
    select 'S'
    union all
    select 'T'
    union all
    select 'U'
    union all
    select 'V'
    union all
    select 'W'
    union all
    select 'X'
    union all
    select 'Y'
    union all
    select 'Z'select top 1 t1.a+t2.a+t3.a+t4.a+t5.a+t6.a+t7.a+t8.a+t9.a+t10.a+t11.a+t12.a
    from @t t1,@t t2,@t t3,@t t4,@t t5,@t t6,@t t7,@t t8,@t t9,@t t10,@t t11,@t t12
    order by t1.newid()
      

  2.   

    这个不太好吧,那还不如把newid()的各个位数用ascii相加,然后换成有效的char,合并,也比这个快吧;我要生成的数据量是亿条级别的,那样不好!
      

  3.   

    declare @bb varchar(50)
    declare @i int
    set @i=1
    declare @temp varchar(50)
    declare @mychar varchar(50)
    declare @a1 int
    declare @a2 int
    declare @a3 int
    set @bb=REPLACE(newid(),'-','')
    set @mychar=''while @i<13
    beginset @temp=substring(@bb,@i*2,2)set @a1=ascii(left(@temp,1))
    set @a2=ascii(right(@temp,1))
    set @a3=(@a1+@a2)-32if  not ((@a3>47 and @a3<58 )or (@a3<91 and @a3>64))
    begin set @a3=@a1
    end 
    set @mychar=@mychar+char(@a3)set @i=@i+1
    endprint @mychar
    go
      

  4.   

    to : Yang_(扬帆破浪) 
    确实不合理当时只想到理论上可以查的到了
    没有想到这茬!   -_-!