日期:2014-05-17 浏览次数:20635 次
declare @t table(idx int)
insert into @t
select 1 union
select 2 union
select 9
select idx from @t
union
select idx+id as idx from @t a
cross apply(
select 1 id
union
select 2
union
select 3
) b
declare @a table(a int)
insert into @a
select 1 union all
select 2 union all
select 9
select * from @a union
select a+1 from @a union
select a+2 from @a union
select a+3 from @a
/*
a
1
2
3
4
5
9
10
11
12
*/
/*这只是思路,如果不只是加1~3的话,可以考虑用while*/
SELECT DISTINCT
idx
FROM ( SELECT idx + id AS idx
FROM @t a
CROSS JOIN ( VALUES ( 0), ( 1), ( 2), ( 3) ) AS t ( id )
) AS temp;
CREATE TABLE A( T1 INT)
INSERT INTO A VALUES (1),(2),(9);
CREATE TABLE #T(T2 INT)
INSERT INTO #T VALUES (1),(2),(3);
SELECT T1 FROM A
UNION
SELECT T1+T2 FROM A,#T