This is my code:
ALTER PROCEDURE [db_owner].[get_checkin_likes]
@likes integer
AS
Select count(*)
from
(
select checkin_id as Checkin, users_id as 'Liked by'
from checkin_likes
where @likes = checkin_id
)
When I execute this command I expect two things:
However, when I try to run the command it returns this:
Msg 102, Level 15, State 1, Procedure get_checkin_likes, Line 9
Incorrect syntax near ')'.
Any suggetions as to how to fix this or why it's happening?
You need to name your subquery; try putting something after the final parenthesis:
ALTER PROCEDURE [db_owner].[get_checkin_likes]
@likes integer
AS
Select count(*)
from
(
select checkin_id as Checkin, users_id as 'Liked by'
from checkin_likes
where @likes = checkin_id
) a
I probably should mention that when you run this query you will only get the count back. I'm not sure of your use-case here, but you can do an OVER and return everything with a count at the end
EDIT:
I would personally do this and have it all in the one record set:
ALTER PROCEDURE [db_owner].[get_checkin_likes]
@likes integer
AS
select checkin_id as Checkin
, users_id as 'Liked by'
, COUNT(checkin_id) OVER () AS total_rows,
from checkin_likes
where @likes = checkin_id
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments