开发者

Trouble with CTE

开发者 https://www.devze.com 2022-12-31 04:28 出处:网络
I am learning CTE, and tried out the following query WITH fooCTE AS ( SELECT TOP 5 f.bar FROM foobar f ) But it\'s displaying an error which is quite incomprehensible.

I am learning CTE, and tried out the following query

WITH fooCTE
AS 
(
SELECT TOP 5 f.bar FROM foobar f
)

But it's displaying an error which is quite incomprehensible.

Msg 102, Level 15, State 1, Line 5
Incorrect syntax near ')'.

Infact when I run the query below, I get the top five values being displayed.

SELECT TOP 5 f.bar FROM foobar f
96.8
92.4
99.3
68.9
74.8

SELECT f.bar from foobar f;
96.8
9开发者_StackOverflow2.4
99.3
68.9
74.8
69.3
94.6
74.8
36.4
92.6
69.4
99.2
39.9
96.2
99.1

I hope am not wrong with the syntax and stuff. Where am I wrong?


You defined fooCTE but you do nothing with it. try:

WITH fooCTE
AS 
(
SELECT TOP 5 f.bar FROM foobar f
)
select * from fooCTE
0

精彩评论

暂无评论...
验证码 换一张
取 消