日期:2014-05-17 浏览次数:20599 次
col1 col2 col3
1 2 3
4 2 3
....
3 2 1
9 8 2
--计算数值表
create table tmp (col1 int,col2 int,co3 int)
go
declare @n int ,@col1 int,@col2 int,@col3 int
set @n=0
while (@n<=504)
begin
select @col1=max(case when rn=1 then number end) ,@col2=max(case when rn=2 then number end) ,@col3=max(case when rn=3 then number end)
from (
select number,rn=row_number() over(order by getdate())
from (
select top 3 number
from master..spt_values
where type='p' and number between 1 and 9 order by checksum(newid())
)k
) z
select @col1,@col2,@col3
if(not exists(select * from tmp where col1=@col1 and col2 = @col2 and co3 =@col3))
begin
set @n = @n+1;
insert tmp select @col1,@col2,@col3;
end
end
go
select * from tmp
drop table tmp
select *
from
(
select left(rtrim(number),1) as col1, substring(rtrim(number),2,1) as col2,right(rtrim(number),1) as col3
from master..spt_values
where type='p'
and number between 123 and 987
) X
where convert(int,col1)*convert(int,col2)*convert(int,col3)>0
and col1<>col2
and col1<>col3
and col2<>col3