0

我的查询如下,其中包含一个子查询:

@catid int

AS
    Select Top(1)
    ID,
    Title,
    Description,
    NewsType,
    CreateTime,
    ISNULL(( ImageURL2 ),'no-pic') As [News-Photo],
    ISNULL(convert(nvarchar(50),ImageTime),'no-date') As [News-Date],
    (select top(5) id,title From News ) as [SpLinks]
    From News 
    Where (NewsType = @catid) and (AllowShow = 'True')
    order by CreateTime Desc

我收到的错误是,当 EXISTS 未引入子查询时,选择列表中只能指定一个表达式。

4

1 回答 1

1

列位置中的子查询只能返回一个值。

如果您要查找多行,请更改您的子查询:

...
(select top(5) id,title From News ) as [SpLinks]
From News 
...

加入:

...
,      SpLinks.id
,      SpLinks.title
from   News 
cross join   
       (
       select  top(5) id
       ,       title 
       from    News 
       ) as SpLinks
...
于 2012-08-03T11:12:49.160 回答