我正在使用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
但不是在SQL Server 2008中-在2008年运行良好。
我必须在SQL Server 2005中做什么才能使其正常工作?
只需使用select
with即可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;
或者,使用递归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;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句