1

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
marc_s
  • 704,970
  • 168
  • 1,303
  • 1,425
Ram
  • 335
  • 5
  • 21

1 Answers1

2

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
marc_s
  • 704,970
  • 168
  • 1,303
  • 1,425