select语句的sql语法错误

时间:2013-04-13 07:37:42

标签: sql-server-2012

这是第一次使用sql server。我在“END”收到错误,因为“END附近的语法不正确”。假如我删除“限制20”,它不播种错误。我该怎么办呢。 我的过程:

ALTER PROCEDURE [dbo].[GettotalApps]
AS 
BEGIN
   SET  XACT_ABORT  ON
   SET  NOCOUNT  ON

   SELECT
       v.appId,
       v.Description,
       (SELECT COUNT(appidorchannelid) 
        FROM ratings r 
        WHERE r.AppIdOrChannelId = v.channelid) AS Channelvotes
   FROM 
       apps v
   WHERE 
       v.ChannelStatusId = 1 
       AND v.IsChannelPrivate = 0
   ORDER BY 
       SubscriberCount DESC 
   limit 20
END

1 个答案:

答案 0 :(得分:2)

SQL Server没有LIMIT关键字 - 这是MySQL特定的非ISO / ANSI标准扩展。

请改为使用TOP关键字:

 SELECT TOP (20)
       v.appId,
       v.Description,
       (SELECT COUNT(appidorchannelid) 
        FROM ratings r 
        WHERE r.AppIdOrChannelId = v.channelid) AS Channelvotes
 FROM 
      apps v