Stored procedure will execute but not save; Visual Studio 2005

  • Hi all, I'm pretty new to this, and any help will be greatly appreciated. I've exhausted my Googling ability with no solution.

    The following stored procedure can be executed via VS 2005's "Design SQL" functionality and it works as I'd expect, but when I try to save it I get an error: "Incorrect syntax near the keyword 'GROUP'."

    SELECT TagName, TagCount

    FROM

    (SELECT TOP (@DisplayNum) t.TagName as TagName, COUNT(1) AS TagCount

    FROM ActivityTagPairs p, Tags t

    WHERE p.TagID = t.ID

    GROUP BY t.TagName

    ORDER BY TagCount DESC)

    GROUP BY TagName, TagCount

    ORDER BY TagName ASC

  • You need to alias the derived table.

  • Holy crap, thanks man!

    If you have any more time, would you care to tell me how I could have figured that out myself? I was totally stumped. This query now executes AND saves just fine:

    ALTER PROCEDURE dbo.GetTagCount

    @DisplayNum int

    AS

    SELECT TagName, TagCount

    FROM

    (SELECT TOP (@DisplayNum) t.TagName as TagName, COUNT(1) AS TagCount

    FROM ActivityTagPairs p, Tags t

    WHERE p.TagID = t.ID

    GROUP BY t.TagName

    ORDER BY TagCount DESC) as d

    GROUP BY TagName, TagCount

    ORDER BY TagName ASC

    RETURN

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply