Ram
Ram

Reputation: 337

sql syntax error for select statement

It's first time to work on sql server. i am getting error at "END" as "incorrect syntax near END". suppose if i remove "limit 20", its not sowing error. how can i fix it. my proc:

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

Upvotes: 1

Views: 320

Answers (1)

marc_s
marc_s

Reputation: 754248

SQL Server doesn't have a LIMIT keyword - that's a MySQL specific, non-ISO/ANSI-standard extension.

Use the TOP keyword instead:

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

Upvotes: 2

Related Questions