SQL Server 2005中的交叉连接值

Con*_*eak 3 sql sql-server sql-server-2005

我正在使用SQL Server 2005,我收到一个错误:

关键字"VALUES"附近的语法不正确.

尝试运行此查询时:

  SELECT T.N 
  FROM Table
  CROSS JOIN (VALUES(1),(2),(3),(4),(5),(6),(7),(8),(9)) as T(N)
  WHERE 1 = 1
Run Code Online (Sandbox Code Playgroud)

但不是在SQL Server 2008中 - 在2008年运行良好.

我需要在SQL Server 2005中做些什么才能使其正常工作?

Gor*_*off 7

只要使用select具有union all代替:

SELECT T.N
FROM Table CROSS JOIN
     (select 1 as n 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
     ) as T(N)
WHERE 1=1;
Run Code Online (Sandbox Code Playgroud)

或者,使用递归CTE,因此您不必键入值:

with t(n) as
      select 1 as n
      union all
      select n + 1
      from t
      where n < 9
     )
select t.n
from table1 cross join
     t
where 1 = 1;
Run Code Online (Sandbox Code Playgroud)